How to use JAVA 8 in Maven Projects

Hi all, when we are using IntelliJ sometimes we need to set the right language level by using module settings. We will set the language setting as JAVA 8 as shown below.

And also in settings, we set the bytecode version as 1.8 as shown below.

In order to do these settings manually, we can also set the java version in our pom.xml and then maven will compile our project with these settings. Here is the way that we can do these settings in pom.xml.

First, we can use properties:

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

Or, we can use maven compiler plugin:

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

Thanks.
Onur Baskirt

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.