22

In maven I can specify a "type" for dependency resolution. I am trying to pull down a tests.jar. How can I do this using Gradle?

I have tried using the Gradle Dependency below, but this does not pull down test.jar.

testCompile(group: 'org.apache.hbase', name: 'hbase', version: '0.94.2', type: 'test-jar')

Maven Dependency:

<dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase</artifactId>
    <version>0.94.2</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>

details: Gradle 1.7

I am trying to pull down "hbase-0.94.2-tests.jar" from Maven Central

Rylander
  • 19,449
  • 25
  • 93
  • 144

3 Answers3

31

Gradle doesn't have a direct equivalent of Maven's <type>, but classifier: 'tests' should work here (instead of type: ...).

Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • 1
    How did you know the classifier would be "tests" ? – BeepDog Feb 19 '15 at 22:55
  • 2
    @BeepDog If you look at how the artifacts are stored in the Maven repository, using a classifier of "tests" should become clear: http://central.maven.org/maven2/org/elasticsearch/elasticsearch/2.2.0/ – rbolkey Feb 18 '16 at 18:40
0

use classifier, example:

    testImplementation("io.vertx:vertx-core") {
      artifact {
        classifier = 'tests'
      }
    }
    testImplementation("io.vertx:vertx-web") {
      artifact {
        classifier = 'tests'
      }
    }

W.Stone
  • 1
  • 1
-1

Two modules in one Root project demo-parent

demo-parent
  |---demo-core
  |---demo-task

if you want to use some testCase common tools from demo-core in demo-task:

project(":demo-task") {
  dependencies {
    implementation(project(":demo-core"))
    
    testImplementation project(':demo-core').sourceSets.test.output
  }
}