IowA
IowA

Reputation: 1056

Gradle changing dependencies by classifier

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?

Upvotes: 2

Views: 2636

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123890

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.

Upvotes: 2

Related Questions