How do I include test sources along side test jar?

I’m outputting the test jar using:

task testJar(type: Jar) {
 	classifier = 'tests'
	from sourceSets.test.output

and had a guess at test sources:

task testSourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'testSources'
    from sourceSets.test.allSource

But when I attempt to get the dependencies in another project I can get the test classes but not the source code

testCompile 'my.other:project:1.7:tests'

In your testCompile dependency declaration, you’re using the tests classifier, so you’re retrieving your testJar jar, which only contains the test output.
You should also add a dependency on your testSource jar:
testCompile ‘my.other:project:1.7:testSources’

Or simply merge your Jars
task testJar(type: Jar) {
classifier = 'tests’
from sourceSets.test.output+sourceSets.test.allSource

1 Like