1

我想--add-exports java.rmi/sun.rmi.server=ALL-UNNAMED为我的 gradle 构建任务向 java 编译器添加参数。我正在使用 gradle kotlin dsl。

下面是更新的 JavaCompiler 任务。

tasks.withType<JavaCompile> {
    val compilerArgs = options.compilerArgs
    compilerArgs.add("--add-exports java.rmi/sun.rmi.server=ALL-UNNAMED ")
}

当我运行gradle compileJava任务时,我得到以下错误。

  • 出了什么问题:任务“:compileJava”执行失败。

错误:无效标志:--add-exports java.rmi/sun.rmi.server=ALL-UNNAMED

  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

我怎样才能解决这个问题?

4

1 回答 1

1

根据javadocoptions.compilerArgs返回List<String>. 所以你可以这样写:

tasks.withType<JavaCompile> {
    val compilerArgs = options.compilerArgs
    compilerArgs.addAll(listOf("--add-exports", "java.rmi/sun.rmi.server=ALL-UNNAMED"))
}

还要确保你有 Java 9+。

于 2021-09-21T04:13:00.393 回答