我有一个多模块的Gradle 6.5项目,其中还包括一些测试夹具代码。为了避免依赖问题,我想在一个地方设置(和维护)版本,并且只引用各个模块中的无版本依赖关系:
subprojects {
apply plugin: 'java'
dependencies {
implementation 'com.google.guava:guava'
constraints {
implementation 'com.google.guava:guava:20.0'
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
}
}
}现在,如果模块包含compilyOnly 'com.google.code.findbugs:jsr305',则根据上面的约束获取版本3.0.2。如果我知道配置(implementation、compileOnly等),就可以很好地工作。
现在的问题是:如何指定适用于所有配置的版本?如果一个模块决定对测试夹具代码使用JSR305注释怎么办?testFixtures 'com.google.code.findbugs:jsr305'失败了,因为没有在任何地方指定版本。我也认为为所有(可能的)配置重复版本规范是一个坏主意:
implementation 'com.google.code.findbugs:jsr305:3.0.2'
testFixturesImplementation 'com.google.code.findbugs:jsr305:3.0.2'
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'有什么捷径可以做到吗?
发布于 2020-06-19 21:39:47
如果使用java-platform plugin修复此问题。
平台:
plugins {
id 'java-platform'
}
dependencies {
constraints {
api 'com.google.guava:guava:20.0'
api 'com.google.code.findbugs:jsr305:3.0.2'
}
}带有测试夹具的常规模块:
plugins {
id "java-test-fixtures"
}
dependencies {
testFixturesImplementation platform(project(':platform-module'))
testFixturesCompileOnly 'com.google.code.findbugs:jsr305'
}./gradlew -q module-with-test-fixtures:dependencies提供了:
[...]
testFixturesCompileClasspath - Compile classpath for source set 'test fixtures'.
+--- project :module-with-test-fixtures (*)
+--- com.google.code.findbugs:jsr305 -> 3.0.2
\--- project :platform-module
\--- com.google.code.findbugs:jsr305:3.0.2 (c)
[...]
(c) - dependency constrainthttps://stackoverflow.com/questions/62468768
复制相似问题