Home >Java >javaTutorial >How to Resolve Test Dependencies in Multi-Project Gradle Configurations?
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:
<code class="groovy">apply plugin: 'java' dependencies { compile project(':ProjectA') }</code>
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:
<code class="groovy">dependencies { ... testCompile project(':A').sourceSets.test.output }</code>
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.
The above is the detailed content of How to Resolve Test Dependencies in Multi-Project Gradle Configurations?. For more information, please follow other related articles on the PHP Chinese website!