I have a Gradle project using the Kotlin Gradle plugin. I want to build a Java 9 module, so my directory structure looks like this:
src/main/java/
- modu
I find it easiest to simply suppress the warnings for use of an automatic module. (In my case I have to use some automatic modules whether I want to or not, so these warnings are just distracting noise.) I have the following in my build.gradle.kts:
val compilerArgs = listOf(
"-Xlint:all", // Enable all warnings except...
"-Xlint:-requires-automatic", // Suppress "requires directive for an automatic module" warnings from module-info.java
"-Xlint:-requires-transitive-automatic" // Suppress "requires transitive directive for an automatic module" warnings from module-info.java
)
// This task will compile all Java code in the target module except for test code.
tasks.compileJava {
doFirst {
options.compilerArgs.addAll(compilerArgs)
}
}
// This task will compile all Java test code in the target module.
tasks.compileTestJava {
doFirst {
options.compilerArgs.addAll(compilerArgs)
}
}