Is there a way how to pass compiler arguments with a command line to Maven?I know I can specify that in compiler-plugin
but I'd like to run Xlint
from command line as well. So I tried something like
mvn clean install -DskipTests=true -DcompilerArgument=-Xlint:deprecation
but with no success.
Are you compiling on the command line? If so, add the -Xlint:unchecked to the command line you're executing, just as the message indicates.
The javac -Xlint options control warnings for all files compiled in a particular run of javac . You may have identified specific locations in source code that generate warnings that you no longer want to see. You can use the @SuppressWarnings annotation to suppress warnings whenever that code is compiled.
This is not an error; it's a warning message. Your program would run as you wrote it. The reason why the compiler is giving you this warning is because you have used a deprecated function call. If you do so, the compiler will tell you which methods are deprecated so you can remove your calls to them.
For this concrete case (deprecation warnings), there actually is a property which can be used from the command line:
mvn clean install -Dmaven.compiler.showDeprecation=true
In contrary to the compilerArgument solution, this also works when using the compiler inside the maven process, not only when using fork=true.
A similarly useful property is maven.compiler.showWarnings
.
You can define a compiler plugin like this:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>${compilerArgument}</compilerArgument>
</configuration>
</plugin>
Then pass parameter from the command line:
mvn -DcompilerArgument=-Xlint:deprecation compile
If you don't pass -DcompilerArgument
, it will not break the build because 'compilerArgument' in the compiler plugin argument will be empty and ignored.
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