When working with multi-project builds in Gradle, it's essential to establish effective dependencies between test code across projects. Consider a scenario where Project A and Project B exist, with Project B relying on components from Project A.
In this situation, the build.gradle for Project B may look like this:
apply plugin: 'java'
dependencies {
compile project(':ProjectA')
}
However, the compileTestJava task fails to compile test code from Project A. This indicates a gap in the configuration needed to access test dependencies from the other project.
To address this issue, Project B's build.gradle can be updated with a testCompile dependency:
dependencies {
...
testCompile project(':A').sourceSets.test.output
}
This new dependency ensures that Project B's test code has access to the compiled test classes from Project A. By using sourceSets.test.output, Gradle resolves the output directory where test classes are placed during the build.
This configuration has been tested successfully with Gradle 1.7. Please note that for Gradle versions 5.6 and above, a different solution is required and is documented separately.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3