How to tell Maven to use Java 8

In pom.xml, defined this maven.compiler.source properties to tell Maven to use Java 8 to compile the project.

1. Maven Properties

Java 8

pom.xml

    <properties>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
    </properties>

Java 7

pom.xml

    <properties>
        <maven.compiler.target>1.7</maven.compiler.target>
        <maven.compiler.source>1.7</maven.compiler.source>
    </properties>

2. Compiler Plugin

Alternative, configure the plugin directly.

pom.xml

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

References

  1. Maven – Setting the -source and -target of the Java Compiler
  2. How to compile Maven project with different JDK version?

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
srini
Guest
srini

With jdk 8 tomcat integration getting lots of issues