【问题标题】:how to hide java 11 Nashorn deprecation warnings如何隐藏 java 11 Nashorn 弃用警告
【发布时间】:2019-04-11 21:56:37
【问题描述】:

我最近升级到了 Java11。有 150 条新的 Nashorn 弃用警告:

Utils.java:31: warning: [removal] NashornScriptEngineFactory in jdk.nashorn.api.scripting has been deprecated and marked for removal
            NashornScriptEngineFactory  factory = new NashornScriptEngineFactory();

是否可以隐藏这些弃用警告?

我尝试过的:

tasks.withType(JavaCompile) {
    options.compilerArgs += '-Xlint:-deprecation'
}

./gradlew build -Dnashorn.option.no.deprecation.warning=true

gradle-wrapper.properties: org.gradle.jvmargs= -Dnashorn.args=--no-deprecation-warning

还有

NashornScriptEngineFactory  factory = new NashornScriptEngineFactory();
ENGINE = factory.getScriptEngine(new String[] {"--no-java --no-deprecation-warning"}, null, className -> false);

我相信JDK-8210140 可能会提到类似的问题。

【问题讨论】:

    标签: java gradle javac java-11 nashorn


    【解决方案1】:

    您看到的警告是由编译器发出的,--no-deprecation-warning 只会抑制创建脚本引擎实例时发出的运行时警告"Warning: Nashorn engine is planned to be removed from a future JDK release"

    你应该可以使用:

    @SuppressWarnings("removal")
    NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
    

    在源代码中完全抑制警告。

    或以其他方式使用:

    -Xlint:-removal
    

    作为编译器参数。这将抑制警告,但您仍会收到基于每个文件的注释。

    【讨论】:

      猜你喜欢
      • 2012-11-20
      • 2019-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-01
      • 2013-11-21
      • 1970-01-01
      • 2018-06-26
      相关资源
      最近更新 更多