Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile Maven project with Xlint

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.

like image 436
Petr Mensik Avatar asked Sep 06 '13 09:09

Petr Mensik


People also ask

How do I run Xlint unchecked?

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.

What is Xlint in Java?

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.

What is Xlint deprecation for details?

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.


2 Answers

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.

like image 167
Paŭlo Ebermann Avatar answered Sep 17 '22 17:09

Paŭlo Ebermann


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.

like image 21
Evgeniy Dorofeev Avatar answered Sep 19 '22 17:09

Evgeniy Dorofeev