Search code examples
javagradlejavacjava-11nashorn

how to hide java 11 Nashorn deprecation warnings


I recently upgraded to Java11. There are 150 new Nashorn deprecation warnings:

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

Is it possible to hide these deprecation warnings?

What I've tried:

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

as well as

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

I believe JDK-8210140 may reference a similar problem.


Solution

  • The warning that you are seeing is emitted by the compiler, the --no-deprecation-warning only suppresses the runtime warning "Warning: Nashorn engine is planned to be removed from a future JDK release" that is emitted when creating the script engine instance.

    You should be able to use:

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

    In the source code to suppress the warning completely.

    Or otherwise use:

    -Xlint:-removal
    

    As a compiler argument. This will suppress the warnings, but you'll still get a note on a per file basis.