Skip to content

Instantly share code, notes, and snippets.

@Fleshgrinder
Created April 2, 2021 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fleshgrinder/ab86a5a9b0c419e140711e141c54d09f to your computer and use it in GitHub Desktop.
Save Fleshgrinder/ab86a5a9b0c419e140711e141c54d09f to your computer and use it in GitHub Desktop.
Simple Version Management for Gradle
gradle.projectsLoaded {
@Suppress("UNCHECKED_CAST")
val versions = java.util.Properties().apply {
load(rootProject.file("version.properties").inputStream())
} as Map<String, String>
allprojects {
// We export the versions so that our tasks can access them
// programmatically as well if required.
extra["versions"] = versions
configurations {
all {
resolutionStrategy {
eachDependency {
if (requested.version == "_") {
val id = requested.module.toString()
if (versions.containsKey(id)) {
useVersion(versions.getValue(id))
} else {
var group = requested.group
do {
if (versions.containsKey(group)) {
useVersion(versions.getValue(group))
break
}
group = group.substringBeforeLast('.')
} while (group.contains('.'))
}
}
// https://github.com/nebula-plugins/gradle-resolution-rules-plugin/issues/97
if (requested.group == "com.google.guava" && requested.version?.contains("-android") == true) {
useVersion(requested.version!!.replace("-android", "-jre"))
because("Android Guava lacks certain optimizations: https://github.com/google/guava/issues/2914")
}
}
}
}
}
}
}
# suppress inspection "UnusedProperty" for whole file
#
# This file is loaded in buildSrc/settings.gradle.kts and used for all
# dependencies, including plugins, to automatically set their version. You can
# either set the version for a complete group, or a particular module.
#
# There is https://jmfayard.github.io/refreshVersions/ which works similarly to
# what we are doing here on our own, plus it can check for new releases. We
# tried adding it but it fails right away. Maybe we can try this again later.
#
# KEEP ALPHABETICALLY SORTED TO AID HUMANS IN SEARCHING!
org.apache.kafka=2.5.1
org.apache.logging.log4j=2.14.0
org.apache.logging.log4j\:log4j-api-kotlin=1.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment