Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

gradle - How to add versions specified in a java platform to all relevant configurations?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...