Artifacts and configurations


(Martin Hauner) #1

I’m trying to create an additional jar in a project for testing only. It should only be created when running the tests.

I’m confused by gradles ‘artifacts’ and ‘configurations’ and do not understand what should work and what should not.

this does not work:

task jarTest (type: Jar) {

classifier = ‘test’

from sourceSets.test.output

}

artifacts {

archives jarTest

}

gradlew test

‘jarTest’ is not called

gradlew build

does call ‘jarTest’.

If I try this

artifacts {

compileTest jarTest

}

gradlew test

to create the jar only for testing, ‘jarTest’ is not called. Why?

The docs also talk about a default configuration (23.5. Dependency management). So this

artifacts {

default jarTest

}

should work too? It doesn’t :wink: How do I say “default”? What would be the difference to ‘archives jarTest’?

Another related question is why use ‘artifacts’ instead of ‘test.dependsOn jarTest’?


(Peter Niederwieser) #2

The ‘artifacts’ block is used to add artifacts to configurations, or in other words, to publish artifacts. If all you want is to have ‘jarTest’ executed before ‘test’, then ‘test.dependsOn jarTest’ is the way to go.