Created
April 2, 2021 14:04
-
-
Save Fleshgrinder/ab86a5a9b0c419e140711e141c54d09f to your computer and use it in GitHub Desktop.
Simple Version Management for Gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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