"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Include Test Dependencies Across Modules in a Multi-Project Gradle Configuration?

How to Include Test Dependencies Across Modules in a Multi-Project Gradle Configuration?

Published on 2024-11-17
Browse:575

How to Include Test Dependencies Across Modules in a Multi-Project Gradle Configuration?

Multi-Project Test Dependencies in Gradle

When working with multi-project configurations in Gradle, managing dependencies for tests across projects can be challenging. This article explores a common issue where test dependencies from one module are not recognized in another module, focusing on the specific example encountered by the user.

The user has a multi-project configuration with two projects, A and B. Project A contains both main and test source code, while Project B depends on the main code from Project A. However, when compiling the test Java code in Project B, the test files from Project A are not included.

The problem lies in the dependency configuration of Project B. To resolve this, the user needs to add a testCompile dependency to Project B's build.gradle file. This will instruct Gradle to include the test sources from Project A as well:

dependencies {
  ...
  testCompile project(':A').sourceSets.test.output
}

This approach has been tested with Gradle version 1.7 and has been deprecated for Gradle versions 5.6 and above. For updated information on managing multi-project test dependencies in Gradle, please refer to the relevant documentation or community resources.

Latest tutorial More>

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