Gradle通过分类器更改依赖项 [英] Gradle changing dependencies by classifier
问题描述
你好,我得到了Maven文件
Hello I got Maven file like so
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
<exclusions>
<!-- Dependency on log4j will be removed in subsequent versions
see https://issues.apache.org/jira/browse/ZOOKEEPER-850 -->
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- TEST -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<!-- There is no current version of zookeeper-test jar -->
<version>3.4.3</version>
<scope>test</scope>
<classifier>tests</classifier>
<exclusions>
<!-- only needed for log4j -->
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
</exclusions>
</dependency>
我想在Gradle上做同样的事情
and I want to do same on Gradle
compile(group: 'org.apache.zookeeper', name: 'zookeeper', version: '3.4.5') {
exclude(group: 'org.slf4j', module: 'slf4j-log4j12')
exclude(group: 'log4j', module: 'log4j')
}
testCompile(group: 'org.apache.zookeeper', name: 'zookeeper', version: '3.4.3', classifier: 'tests') {
exclude(module: 'jmxri')
exclude(module: 'jmxtools')
}
但是Gradle仍然尝试采用最新版本,因此在尝试运行测试时出现错误.知道在Gradle中是如何做到的吗?
But Gradle still tries to take newest version so I am getting errors when trying to run tests. Any idea how this is done in Gradle?
推荐答案
Gradle在每个模块的基础上执行冲突解决,但是分类器仅影响工件,而不影响模块.(换句话说, zookeeper-tests
没有自己的POM.)一种解决方案是切换到 zookeeper-3.4.3
(除了 zookeeper-3.4.3-tests
).另外,如果您有二进制存储库管理器,则可以更改两个依赖项之一的组或工件ID.
Gradle performs conflict resolution on a per-module basis, but a classifier only affects the artifact, not the module. (In other words, zookeeper-tests
doesn't have its own POM.) One solution is to switch to zookeeper-3.4.3
(in addition to zookeeper-3.4.3-tests
) for the test class path. Alternatively, if you have a binary repository manager, you could change the group or artifact ID for one of the two dependencies.
这篇关于Gradle通过分类器更改依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!