Multi-Project Test Dependencies in Gradle
When working with multi-project configurations, it's common to encounter issues with test dependencies across projects. Let's consider the following scenario:
Project Layout:
Project A
Project B
Problem:
In Project B's build.gradle file:
<code class="gradle">apply plugin: 'java' dependencies { compile project(':ProjectA') }</code>
While the compileJava task successfully compiles the main source, the compileTestJava task fails to compile the test files in Project A.
Solution (Deprecated for Gradle 5.6 and above):
To resolve this issue, add a testCompile dependency in Project B:
<code class="gradle">dependencies { ... testCompile project(':A').sourceSets.test.output }</code>
Note: This solution is deprecated for Gradle 5.6 and above. For newer versions, refer to the recommended approach provided in the accepted answer.
The above is the detailed content of How to Handle Test Dependencies in Multi-Project Gradle Configurations?. For more information, please follow other related articles on the PHP Chinese website!