Gradle dependency with test classifier

Viewed 304

I've been trying to reference an artefact without luck.

With maven I have no problem doing this:

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka_2.13</artifactId>
    <version>3.0.0</version>
    <classifier>test</classifier>
</dependency>

Maven selects the correct artefact.

However, with gradle, it always seems to include the artefact without the classifier, no matter what I try:

implementation 'org.apache.kafka:kafka_2.13:3.0.0:test'

I have read the gradle documentation and it suggests this syntax, maybe it has something to do with this specific artefact?

Update

My goal is to use spring-kafka-test. Our internal artefact repository is not set up to use pom resolution, which is why I need to add transitives manually.

I've ruled out the fact that it might be our internal repository by only using maven central; and I get the same results.

2 Answers

But

Your assumptions about maven were also wrong:

Maven Pulls All Dependencies Screenshot

Maven pulls all! (In module-test-parents no dependencies defined.)

To achieve the same (and even more) in maven we'd also have to:

  <dependencies>
    <dependency>
      <groupId>org.apache.kafka</groupId>
      <artifactId>kafka_2.13</artifactId>
      <version>3.0.0</version>
      <classifier>test</classifier>
      <exclusions>
        <exclusion> <!--sledge hammer -->
          <groupId>*</groupId>
          <artifactId>*</artifactId>
        </exclusion>
        <!-- or selectively ... -->
      </exclusions>
    </dependency>
  </dependencies>

In gradle the according would be (tested):

implementation ('org.apache.kafka:kafka_2.13:3.0.0:test'){
  exclude group: '*'
}
Related