[英]How can I set gradle resolutionStrategy for only the release build?
I'm developing an android app where I want the release build to fail if there is a dependency version conflict. 我正在开发一个android应用,如果存在依赖版本冲突,我希望发布构建失败。 If I want to enable it for all builds, I can do this:
如果要为所有构建启用它,可以执行以下操作:
configurations.all {
resolutionStrategy {
failOnVersionConflict()
}
}
However I don't want to enable it for debug builds. 但是我不想为调试版本启用它。 I can't find any documentation on how to do that.
我找不到有关如何执行此操作的任何文档。 I've tried:
我试过了:
configurations.each {
if (it.name.startsWith("release")) {
it.resolutionStrategy {
failOnVersionConflict()
}
}
}
But it doesn't apply. 但这并不适用。 I've even tried what I thought would be the equivalent of the first example - but this has no effect:
我什至尝试了我认为等同于第一个示例的方法-但这没有效果:
configurations.each {
it.resolutionStrategy {
failOnVersionConflict()
}
}
I'm simply switching .all
for .each
here, but failOnVersionConflict
doesn't apply even though the code is executed. 我简单地切换
.all
的.each
在这里,但failOnVersionConflict
即使执行的代码并不适用。
What am I doing wrong? 我究竟做错了什么?
It should work in the following way: 它应该以以下方式工作:
apply plugin: 'java'
configurations.compile.resolutionStrategy {
failOnVersionConflict()
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:23.0'
compile 'com.google.guava:guava:22.0'
}
task deps(type: Copy) {
from configurations.compile
into('deps')
}
When you run gradle deps
then it should fail with version conflict. 当您运行
gradle deps
它将因版本冲突而失败。 If you comment out configuration block guava version 23.0 will be copied. 如果您注释掉配置块,番石榴版本23.0将被复制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.