I have a multi-project configuration and I want to use gradle.
My projects are like this:
Project A
src/main/java
src/test/java
Project B
src/main/java
(depends on src/main/java
on Project A) src/test/java
(depends on src/test/java
on Project A) My Project B build.gradle
file is like this:
apply plugin: 'java' dependencies { compile project(':ProjectA') }
The task compileJava
work great but the compileTestJava
does not compile the test file from Project A.
One of the best features in Gradle for JVM-related projects is its ability to run tests in parallel. As discussed in the Gradle documentation, this implemented by setting the maxParallelForks property inside a test block in the build.
Simply open the gradle tab (can be located on the right) and right-click on the parent in the list (should be called "Android"), then select "Refresh dependencies". This should resolve your issue.
This is now supported as a first class feature in Gradle. Modules with java
or java-library
plugins can also include a java-test-fixtures
plugin which exposes helper classes and resources to be consumed with testFixtures
helper. Benefit of this approach against artifacts and classifiers are:
:modul:one
plugins { id "java-library" // or "java" id "java-test-fixtures" }
package com.example; public class Helper {}
:modul:other
plugins { id "java" // or "java-library" } dependencies { testImplementation(testFixtures(project(":modul:one"))) }
package com.example.other; import com.example.Helper; public class SomeTest { @Test void f() { new Helper(); // used from :modul:one's testFixtures } }
For more info, see the documentation:
https://docs.gradle.org/current/userguide/java_testing.html#sec:java_test_fixtures
It was added in 5.6:
https://docs.gradle.org/5.6/release-notes.html#test-fixtures-for-java-projects
In Project B, you just need to add a testCompile
dependency:
dependencies { ... testCompile project(':A').sourceSets.test.output }
Tested with Gradle 1.7.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With