Created
October 15, 2014 13:35
-
-
Save aalmiray/ccf26a213cb70b671078 to your computer and use it in GitHub Desktop.
Gradle multi-project build where project2's test classes depend on project1's test classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
├── build.gradle | |
├── project1 | |
│ ├── build.gradle | |
│ └── src | |
│ └── test | |
│ └── java | |
│ └── sample | |
│ └── Foo.java | |
├── project2 | |
│ ├── build.gradle | |
│ └── src | |
│ └── test | |
│ └── java | |
│ └── sample | |
│ └── BarTest.java | |
└── settings.gradle | |
== BarTest.java | |
package sample; | |
import org.junit.Test; | |
import static org.junit.Assert.*; | |
public class BarTest { | |
@Test | |
public void doit() { | |
assertNotNull(new Foo()); | |
} | |
} | |
== build.gradle (project1) | |
task testJar(type: Jar) { | |
classifier 'test' | |
from sourceSets.test.output | |
} | |
== build.gradle (project2) | |
dependencies { | |
compile project(':project1') | |
testCompile files(project(':project1').testJar.archivePath) | |
} |
I'd actually add a configuration to project1 (e.g. tests
) and then register the JAR task as outgoing artifact.
configurations {
tests
}
artifacts {
tests testJar
}
Then you reference it in project2 like this:
dependencies {
testCompile project(path: ':project1', configuration: 'tests')
}
First I think it's a very bad idea to design a project which depends on test code of another project.
Now that I've said it, I've migrated a large project from Maven to Gradle in which this bad idea was implemented and I've found that @bmuschko solution was the right way because it accounts for transitive dependencies while @akhikhl solution doesn't.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about:
testCompile project(':project1').sourceSets.test.output