Home > Java > javaTutorial > body text

How to Handle Test Dependencies in Multi-Project Gradle Configurations?

Linda Hamilton
Release: 2024-10-26 09:25:30
Original
243 people have browsed it

How to Handle Test Dependencies in Multi-Project Gradle Configurations?

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

    • src/main/java
    • src/test/java
  • Project B

    • src/main/java (depends on Project A's main source)
    • src/test/java (depends on Project A's test source)

Problem:
In Project B's build.gradle file:

<code class="gradle">apply plugin: 'java'
dependencies {
  compile project(':ProjectA')
}</code>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!