Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass -Xlint:deprecation or -Xlint:unchecked to Maven?

Tags:

java

maven

When I build my project I get errors like:

[INFO] SomeClass.java: Some input files use or override a deprecated API.
[INFO] SomeClass.java: Recompile with -Xlint:deprecation for details.
[INFO] SomeClass.java: Some input files use unchecked or unsafe operations.
[INFO] SomeClass.java: Recompile with -Xlint:unchecked for details.

But when I put -Xlint:deprecation or -Xlint:unchecked in my MAVEN_OPTS or .mvn/maven.config I get:

$ MAVEN_OPTS="-Xlint:unchecked " mvn -B clean test 
Unrecognized option: -Xlint:unchecked
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

What gives?

like image 574
Craig Ringer Avatar asked Dec 23 '22 23:12

Craig Ringer


1 Answers

-Xlint is a compiler option, not a maven option or jvm option.

On the command line maven accepts -Xlint but it treats it as the -X maven option ("debug") and ignores the rest. So it doesn't have the expected effect.

In the specific case of these two compiler options you can set Maven properties that result in the desired compiler options being set. Put these in your project's .mvn/maven.config, MAVEN_OPTS env var, or on the command line:

-Dmaven.compiler.showWarnings=true
-Dmaven.compiler.showDeprecation=true

See maven compiler plugin.

You can also use the compilerArgs property in your pom.xml or a Maven settings.xml user-defined profile. I don't see a way to set that List valued property as a system property. You can't use compilerArgument or compilerArguments either, they don't have user properties.

You may also find it useful to control the compiler's logging level; for example, you can silence these warnings with:

-Dorg.slf4j.simpleLogger.log.org.apache.maven.plugin.compiler.CompilerMojo=warn

Note that explicitly setting -Dmaven.compiler.showWarnings=false will not suppress the -Xlint messages. See How can I suppress javac warnings about deprecated api? . Maven doesn't appear to offer a way to set the relevant properties -Xlint:-deprecated -Xlint:-unchecked on the command line. You can't set them directly settings.xml either because you can't set individual plugin properties. It has to be the pom.xml.

like image 141
Craig Ringer Avatar answered Jan 07 '23 11:01

Craig Ringer