简体   繁体   中英

How to use maven compiler plugin to grab all the warnings in eclipse

Currently, I'm using maven pligin to grab eclipse warnings and print them on the console, for example

 HashMap<T, V> list = new HashMap<>(); 

The variable list has never been used, so the eclipse will underline it with yellow line as a warning. And when I compile with maven plugin, this warning will be reported on the console.

>        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <compilerId>eclipse</compilerId>
                <source>1.7</source>
                <target>1.7</target>
                <optimize>true</optimize>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.plexus</groupId>
                    <artifactId>plexus-compiler-eclipse</artifactId>
                    <version>2.3</version>
                </dependency>
             </dependencies>
        </plugin>

And when I input the command like 'mvn clean compile', it will print

[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ iqunxing-cep --- [INFO] Changes detected - recompiling the module! [WARNING] D:\\XXX.java:[42,1412] The value of the local variable list is not used

I'm using Eclipse, and as you all know, there are quite a lot of warnings that you can set in preference - java - compiler - error/warning.

Based on my current setting, codes like parameter assignment is also underlined. Like in the following case, the variable i is underlined, too.

public void name(int i) { i = 3; }

So my question is, how can I make the maven compiler print all the warnings on the console? Because right now, I have several warnings in my codes. But it only prints part of the warnings. For example: I have a variable called 'list' that never been used which will be printed. I also assign the parameter 'i' within a method which is a warning. However, it won't be printed on the console. Should I add more tags into the pom.xml as parameters of maven-compiler-plugin?

If your project is already a Maven project and you've imported it into Eclipse as a Maven Project, you can right click it, Run As ... / Maven Build... and then enter you goals, eg clean compile, or select from the typical goals in the menu. It will use Maven to execute your goals and output to the console.

May u check following link?If yes, please confirm this answer. http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#showWarnings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM