Gradle changing dependencies by classifier

青春壹個敷衍的年華 提交于 2021-02-10 04:54:46

问题


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>

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')
}

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?


回答1:


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.



来源:https://stackoverflow.com/questions/17230989/gradle-changing-dependencies-by-classifier

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!