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
340 views
in Technique[技术] by (71.8m points)

Is it possible to set a dependencySet entry's classifier using Spring's Gradle dependency management plugin

I have a project that uses the Spring Dependency Management Plugin in a multi-project Gradle build to specify consistent dependency versions for the projects.

Per the documentation, when multiple dependencies share the same group & version, a dependency set should be used:

When you want to provide dependency management for multiple modules with the same group and version you should use a dependency set. Using a dependency set removes the need to specify the same group and version multiple times, as shown in the following example:

dependencyManagement {
     dependencies {
          dependencySet(group:'org.slf4j', version: '1.7.7') {
               entry 'slf4j-api'
               entry 'slf4j-simple'
          }
     }
}

The project uses two dependencies that share a group and version, but one of the items also specifies a classifier:

dependencies {
  annotationProcessor 'com.querydsl:querydsl-apt:4.2.2:general'
  implementation 'com.querydsl:querydsl-mongodb:4.2.2'
}

If there's a way to use a dependencySet in this case, I haven't found it in the documentation or an online search:

dependencyManagement {
    dependencies {
        dependencySet(group:'com.querydsl', version: '4.2.2') {
            entry 'querydsl-apt' // Can I specify that this uses the "general" classifier?
            entry 'querydsl-mongodb'
        }
    }
}

So in short, is there a way to use a dependencySet when one of the dependencies requires a classifier, and what is the syntax for doing so?


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

1 Reply

0 votes
by (71.8m points)

Issue #67 for the Dependency Management Plugin requests this feature. The issue was closed by the maintainers with a status of "declined" by the plugin maintainers:

It's impossible to implement this while classifiers remain a second class citizen in Gradle. I don't expect that will change any time soon (things haven't improved in Gradle 3.0) so, with some regret, I'm going to close this.

Follow-up conversation in that issue suggest that the underlying Gradle issue is still not resolved in Gradle 6.

This means that not only can classifiers not be specified using dependencySet, they cannot be specified using dependency entries within the dependencyManagement section either:

dependencyManagement {
    dependencies {
        dependency 'com.querydsl:querydsl-apt:4.2.2:general' // INVALID
        dependency 'com.querydsl:querydsl-mongodb:4.2.2'
    }
}

What's worse, there is no warning or failure emitted, so the fact that it's not using the specified version with a classifier is not made clear to the user.

So to answer the question, the usage of classifiers in the dependencyManagement plugin is not supported since Gradle does not provide an API for the plugin to access the classifier. Therefore, dependency versions with classifiers cannot be specified in the dependencyManagement section either directly using dependency or as a group using dependencySet.


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

...