I am having a issue with gradle 8.0.2 using JVM Test Suite plugin. The integration test cannot get the dependencies from the main project.
The build.gradle looks like this. The integration test classes give compilation error as it can't get the dependencies from main project using 'implementation project()
id 'java'
id 'java-library'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation 'com.fasterxml.uuid:java-uuid-generator:4.1.0'
}
testing {
suites {
integrationtest(JvmTestSuite) {
dependencies {
implementation project()
}
}
}
}```
How the Test Suites plugin works
The documentation on the plugin says:
Therefore, when you depend on
implementation project()in a new test suite you will be able to see public types defined in the main source set's code, plus any dependencies declared in theapiconfiguration – but not those declared inimplementation.The logic behind this, it would seem, is that integration tests should only see the same types that an consuming project would by default. This makes sense since they are "integration tests", testing the external, not internal, API of the project. The regular
testsource can see the regularimplementationdependencies if such tests are needed.Your case
If you do want to override this convention and access an external dependency (in your case
java-uuid-generator) in a set of integration tests, I suggest one of the following options:api:implementationdependency configuration extend the mainimplementationconfiguration, thereby picking up the latter's dependencies and not altering the API a consuming project would see:implementationconfiguration of the integration tests. This might seem odd, but it's consistent with Gradle's logic: the fact the integration tests need the dependency is conceptually different to the fact the main code needs the dependency: