I have converted our project from the spring dependency management plugin to using a java platform subproject to fix dependency versions project-wide.
For the most part this was easy.
Before we had this in the root level build.gradle:
plugins {
id 'io.spring.dependency-management'
}
allprojects {
apply plugin: 'io.spring.dependency-management'
plugins.with {
withType(JavaPlugin) {
dependencyManagement {
... version specifications, both importing maven boms and settings individual versions ...
It was straightforward to move all the version specifications to a subproject of type "java platform".
However the spring dependency management applies its versions to all relevant configurations automatically.
With the java platform approach I ended up with
allprojects {
plugins.with {
withType(JavaPlugin) {
dependencies {
// For some reasons it confuses these plugins if we add our "gradle bom" to them (but then codenarc needs it)
def excludedConfigurations = [
'checkstyle', 'pmd', 'jacocoAgent', 'spotbugs', 'spotbugsPlugins', 'spotbugsSlf4j', 'jacocoAnt'
] as Set
configurations.all { conf ->
if(conf.canBeResolved && !(conf.name in excludedConfigurations)) {
add(conf.name, enforcedPlatform(project(":ggw-cosmo-dependencies")))
}
}
We have a lot of dependencies in our project, some coming from plugins (like xjc from a jaxb plugin) and some custom
configurations (e.g. for running tools during the build with a separate classpath or for war overlay), so specifying the
'included' configurations instead of the 'excluded' ones like in the code sample above needs a longer list, that would also be
more volatile.
question from:
https://stackoverflow.com/questions/66062899/how-to-add-versions-specified-in-a-java-platform-to-all-relevant-configurations 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…