Do Kotlin 1.2.10 and Java 9 have opposite rules regarding automatic modules?

后端 未结 2 390
耶瑟儿~
耶瑟儿~ 2021-01-05 08:16

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         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-05 08:57

    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)
        }
    }
    

提交回复
热议问题