I'm trying to create Java application using Java module system with gradle. I use this plugin: https://github.com/java9-modularity/gradle-modules-plugin as recommended by gradle. Java sources compile properly and use module-info.java as expected. However, my unit test does not work anymore. I want to use assertJ which is causing problems now. When I try to compile test classes, I'm getting this error:
error: package org.assertj.core.api is not visible import static org.assertj.core.api.Assertions.assertThat; ^ (package org.assertj.core.api is declared in module org.assertj.core, but module module.test.main does not read it)
I tried to set
tasks {
test {
extensions.configure(TestModuleOptions::class) {
runOnClasspath = true
}
}
}
but this does not change anything.
I have created temporary github repo for anyone to reproduce the issue: https://github.com/Mariusz-v7/tmp-module-test
How to fix my unit tests now?
As documented in the plugin documentation, by default testing happens on the module path.
What you changed is about running tests. However test compilation also happens on the module path, you thus need the test dependencies to be properly imported by your module. Which is what the error is telling you.
As an alternative, you could try the native support in upcoming Gradle 6.4, a release candidate is available