Composite build with test sources

I have proj2 depending on proj1. proj2 also requires proj1 for test sources because the test classes in proj2 depending on test classes in proj1. I am trying to get this to work using composite build functionality without success.

proj2: settings.gradle

includeBuild file('../proj1/')

proj2: build.gradle

compile 'app1:proj1:+'
testCompile 'app1:proj1:+:testArtifacts'

proj1: build.gradle

configurations {
    testArtifacts.extendsFrom testRuntime
}

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

When i try this i get the error in intellij

Error:Can't parse gradle module dependency 'DefaultIdeaModuleDependency{scope='IdeaDependencyScope{scope='COMPILE'}', targetModuleName='proj1', exported=false}'. Reason: referenced module is null

and this error on the command line

* What went wrong:
Could not resolve all dependencies for configuration ':testCompileClasspath'.
> Could not find proj1-testArtifacts.jar (app1:proj1:unspecified).

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Is this possible?

Whilst not an answer to your question, it’s worth noting that nebula have deprecated their nebula.test-jar plugin for the following reason

We will be removing this functionality in the next major release. We feel it is better to create a project for any shared test harnesses than to try and create an extra jar out of the test classes.

Composite build does not yet support custom configurations or publications.

Thanks for your replies. Will support for this be coming? If so do you have a time frame?

Yes it will come, I don’t have a clear time frame though. Definitely not this year anymore.

What the status of that?

@st_oehme What is the status of this? is it done? if yes how it can be configured?

test of proj2 should not depend on test of proj1.
test of proj1 should only contain tests for proj1, not for proj2.
IF you have code like test fixtures, base classes, utilities, and so on, you should use the java-test-fixtures plugin which defines a test fixtures source set where you are meant to put test code that should also be shared with other projects.

Of course you could expose the test source set in the same manner like that plugin does for the testFixtures source set, just look at its sources, but it would be cleaner to not mix the responsibilities. :slight_smile: