2

I want to see the java code warnings when I build my project from the command line using maven.

Currently, when I use eclipse, the IDE highlights the warns for me. So I want to have that behavior when I build my project using maven.

Thanks in advance. Juan

2 Answers2

2

IDE-like level of warnings cannot be achieved with javac compiler thus you have to go with a non-javac one. Below is a POM snippet:

<plugin>
    <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>
        <compilerArguments>
            <org.eclipse.jdt.core.compiler.problem.fatalOptionalError>disabled</org.eclipse.jdt.core.compiler.problem.fatalOptionalError>
            <org.eclipse.jdt.core.compiler.problem.forbiddenReference>ignore</org.eclipse.jdt.core.compiler.problem.forbiddenReference>
        </compilerArguments>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-compiler-eclipse</artifactId>
            <version>2.3</version>
        </dependency>
    </dependencies>
</plugin>
S. Pauk
  • 5,208
  • 4
  • 31
  • 41
  • Further to Sergey’s suggestion above, I had to do the following two things: #1: Use Eclipse quick-fix to automatically update the POM with a new configuration (http://stackoverflow.com/a/14809920/1617124). #2: Resolve Maven warnings by wrapping the new configuration into an ‘only-eclipse-profile’ (http://stackoverflow.com/a/23707050/1617124) – Lars Nov 07 '16 at 10:31
0

You just need to add <showWarnings>true</showWarnings> to maven compiler plug-in in your pom.xml.

Please have a look at the maven compiler documentation here.

geekprogrammer
  • 1,108
  • 1
  • 13
  • 39
  • This is not working for me. I made a new maven project with a single class and a variable that is never used, that should throw an unused variable warning, but it does not – Juan Martin Desimoni Mar 18 '15 at 18:44