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.
You can use the @SuppressWarnings annotation to suppress warnings whenever that code is compiled. Place the @SuppressWarnings annotation at the declaration of the class, method, field, or local variable that uses a deprecated API.
Deprecation warnings are a common thing in our industry. They are warnings that notify us that a specific feature (e.g. a method) will be removed soon (usually in the next minor or major version) and should be replaced with something else.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With