Deploying test jars with Ivy

I need to deploy 4 jars from each of my projects: the binary and source jars from the “main” sourceSet, and the binary and source jars from the “test” set. I currently have this set up as follows:

task jarTests(type: Jar, dependsOn: testClasses) {

appendix = ‘tests’

from sourceSets.test.output

}

task jarSources(type: Jar) {

classifier = ‘sources’

from sourceSets.main.allSource

}

task jarTestSources(type: Jar) {

classifier = ‘sources’

appendix = ‘tests’

from sourceSets.test.allSource

}

artifacts {

archives jarTests

archives jarSources

archives jarTestSources

}

My Ivy artifactPattern is ‘…/[organization]/[module]/[revision]/[artifact]-revision.[ext]’

Let’s assume the organization is Foo, the project is MyProject, and the version is 1.0.1. When I run “gradle upload” from the myproject directory, Gradle creates: *

…/foo/myproject/myproject-1.0.1.jar *

…/foo/myproject/myproject-1.0.1-sources.jar *

…/foo/myproject/myproject-tests-1.0.1.jar *

…/foo/myproject/myproject-tests-1.0.1-sources.jar

Unfortunately, when I try to use the myproject-tests artifact from another project, Ivy can’t find it (since it’s not in foo/myproject-tests, it’s in foo/myproject). My dependencies line looks like:

testCompile group: ‘foo’, name: ‘foo-tests’, version: ‘1.0.1’

I can sort of fix it by changing the Ivy pattern from …/[organization]/[module]/… to …/[organization]/[artifact]/…, but that just seems hackish (not to mention messing up ivy.xml).

What is the right way to do this?

My dependencies line looks like: testCompile group: ‘foo’, name: ‘foo-tests’, version: ‘1.0.1’

The line looks ok to me. I suspect there’s a problem with configurations. Can you paste the resulting ivy.xml?

We’re working in the area of dependency management at the moment so that it’s going to be easier to resolve such situations (be it better documentation or DSL improvements)

I solved the problem by creating a “tests” configuration in Foo:

configurations {

tests

}

artifacts {

archives jarTests

archives jarSources

archives jarTestSources

tests jarTests

tests jarTestSources

}

And depending on that configuration in Bar:

testCompile group: ‘foo’, name: ‘foo’, version: ‘1.0.1’, configuration: ‘tests’