I have two projects (call them Foo and Bar). Both projects have "main" code
as well as "test" code. The problem is that project Bar depends on both the
"main" and the "test" code from project Foo.
Both projects are being uploaded to Maven. For reasons I won't get into, I
can't use a multiproject build - these have to be two completely independent
builds.

I've managed to convince Foo to produce a second jar containing the tests
with the following:

task jarTests(type: Jar, dependsOn: testClasses) {
>   classifier = 'tests'
>   from sourceSets.test.classes
> }
>
> artifacts {
>   archives jarTests
> }
>

These jars get uploaded to Maven (as foo-1.0-SNAPSHOT.jar and
foo-1.0-SNAPSHOT-tests.jar) without any problem. The problem comes with
project Bar.

Project Bar's build.gradle contains the following:

> dependencies {
>   compile 'foo:foo:1.0-SNAPSHOT'
>   testCompile 'foo:foo:1.0-SNAPSHOT:tests'
>   testCompile 'junit:junit:4.8.2'
> }
>

The main code compiles fine, but the test code won't compile. When I look at
the classpath, I see foo-1.0-SNAPSHOT-tests.jar being included, but
foo-1.0-SNAPSHOT.jar isn't. If I comment out the testCompile line,
foo-1.0-SNAPSHOT.jar makes it into the classpath (but I lose the tests jar).
If I add "testCompile 'foo:foo:1.0-SNAPSHOT'" after the tests line, it makes
it into the classpath, but I lose the tests jar. Is there any way to tell
Gradle (or Ivy or whatever) that I want both?

Failing that, is there a way to move the tests into a completely separate
artifact? I've poked a little at addFilter(), but I don't understand what's
actually going on there.

Thank you.

Reply via email to