Search code examples
mavenjavaccompiler-warnings

Enable javac warnings in maven build


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


Solution

  • 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>