Maven - Setting Java Compiler Arguments

[Updated: Aug 13, 2017, Created: Feb 12, 2016]

We can set Java compiler (javac) options and arguments in pom.xml.

Use compilerArgs. This sets the arguments to be passed to the compiler.

Example:

 <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                    <compilerArgs>
                        <arg>-g</arg>
                        <arg>-Xlint</arg>
                     </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>

See Also