How can I retrieve dependencies in pom test scope transitively?


(gretar arnason) #1

Let’s say I have dependency with a pom file in a repository like:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>mygroup</groupId>
 <artifactId>myartifact</artifactId>
 <version>1.0.0</version>
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.8.2</version>
   <scope>test</scope>
  </dependency>
 <dependencies>
</project>

What I’m looking for is to somehow create a new configuration and add the ‘mygroup:myartifact:1.0.0’ to the group in such a way that it will resolve the junit jar. Example build.gradle:

repositories {
...
}
  configurations {
    test
}
  dependencies {
    test 'mygroup:myartifact:1.0.0'
}
  task dump << {
    configurations.test.files.collect{ it.name}.sort().each { println it }
}

Is there a way to config this in such a way that ‘gradle dump’ will give me result: junit-4.8.2.jar myartifact-1.0.0.jar

Footnote: I’m using the name test for configuration for brevity, I expect it will clash with test task when applying java plugin.


(René Groeschke) #2

Hello gretar, you have to set the “configuration” you want to resolve when looking for a specific scope. for this you have to use the map syntax for delcaring your dependencies:

test group:'mygroup', name:'myartifact', version:'1.1.0', configuration:'test'

unfortunately this does not include myartifact itself so you still need “test ‘mygroup:myartifact:1.1.0’” in your dependency block.

best regards, René


(gretar arnason) #3

Yes! I knew this had to be simple :). Now working like a charm. Thank you so much. Saved my weekend.

best regards gretar