如何为所有 Gradle 子模块启用 --enable-preview 以便它也保留在 IntelliJ IDEA 中?

And*_*ani 4 java intellij-idea preview gradle

使用以下 Gradle 设置


sourceCompatibility = 1.12
targetCompatibility = 1.12

tasks.withType(JavaCompile) {
    options.incremental = true
    options.compilerArgs 
Run Code Online (Sandbox Code Playgroud)

the project will be compiled, the tests executed and the artifacts built on JDK 12. However, in IntelliJ with the following common project structure

project
|_moduleA
  |_main
  |_test
|_moduleB
  |_main
  |_test
Run Code Online (Sandbox Code Playgroud) 语言级别设置为12(预览版) -仅切换表达式,项目和两个模块都获得此语言级别。然而,主模块测试模块会丢失设置,IDEA 表示刷新 Gradle 项目时这些设置也会丢失。那么如何应用--enable-preview设置以便源模块也保留该设置呢?

cat*_*h22 5

我遇到了同样的问题,按照gradle 文档解决了:

tasks.withType(JavaCompile) {
    options.compilerArgs += "--enable-preview"
}
tasks.withType(Test) {
    jvmArgs += "--enable-preview"
}
tasks.withType(JavaExec) {
    jvmArgs += "--enable-preview"
}
Run Code Online (Sandbox Code Playgroud)