Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven How to show warnings of codes when compiling

Tags:

java

maven

I'm using maven to build a new project. There are some warnings in my codes which are underlined by yellow line. I wish maven could report these warnings in console. How can I accomplish that? Can I just add some parameters in the command such as mvn -XXX clean compile?

like image 756
Russell Yu Avatar asked Mar 07 '17 06:03

Russell Yu


People also ask

What is annotationProcessorPaths in Maven?

<annotationProcessorPaths>The detection itself depends on the configuration of annotationProcessors. Each classpath element is specified using their Maven coordinates (groupId, artifactId, version, classifier, type). Transitive dependencies are added automatically.

What does mvn clean command do?

mvn clean This command cleans the maven project by deleting the target directory.


2 Answers

<showDeprecation>
Sets whether to show source locations where deprecated APIs are used.

  • Default value is: false
  • User property is: maven.compiler.showDeprecation

<showWarnings>
Set to true to show compilation warnings.

  • Default value is: false
  • User property is: maven.compiler.showWarnings

-- Maven Doku

As simple as mvn clean install -Dmaven.compiler.showDeprecation=true -Dmaven.compiler.showWarnings=true all in one line.

You could even remove the =true part because, when you add a maven parameter with -D it automatically sets its value to true, if not set to something else.

like image 126
Lusk116 Avatar answered Oct 04 '22 17:10

Lusk116


With maven 3.3.9, using the maven-compiler-plugin and Java 1.8, you need a <configuration> section like the following:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <executions>
        <execution>
            <id>compile</id>
            <phase>compile</phase>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
        <execution>
            <id>testCompile</id>
            <phase>test-compile</phase>
            <goals>
                <goal>testCompile</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <compilerArgument>-Xlint:all</compilerArgument>
        <showWarnings>true</showWarnings>
        <showDeprecation>true</showDeprecation>
    </configuration>
</plugin>

I got this answer from here when none of the above worked for me: http://frequal.com/java/EnableWarningsInMaven.html

like image 37
GlenPeterson Avatar answered Oct 04 '22 18:10

GlenPeterson