Home  >  Article  >  Java  >  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?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-26 19:16:30700browse

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.

The above is the detailed content of How to Include Test Dependencies Across Modules in a Multi-Project Gradle Configuration?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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