Gradle 为多个配置指定渐变版本约束
我有一个多模块Gradle 6.5项目,其中还包括一些测试夹具代码。为了避免依赖性问题,我想在一个地方设置(并维护)版本,只需参考各个模块中的无版本依赖性:Gradle 为多个配置指定渐变版本约束,gradle,Gradle,我有一个多模块Gradle 6.5项目,其中还包括一些测试夹具代码。为了避免依赖性问题,我想在一个地方设置(并维护)版本,只需参考各个模块中的无版本依赖性: subprojects { apply plugin: 'java' dependencies { implementation 'com.google.guava:guava' constraints { implementation 'com.google.gu
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'
}
}
}
现在,如果一个模块包含compileyonly'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'
有快捷方式吗?如果使用修复此问题
站台:
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模块与测试夹具:依赖关系
给出:
[...]
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 constraint
如果已修复此问题,请使用
站台:
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模块与测试夹具:依赖关系
给出:
[...]
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 constraint