Enforce Java version on Maven

0
3090
Enforce Java version on Maven
Enforce Java version on Maven

In a Maven project for managing Java application, to enforce usage of a specific Java version, you will need to add configuration option to the maven-compiler-plugin.

To achieve this, simply add the appropriate source and targetoptions to the maven-compiler-plugin, for example:


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

Change the source and targetto the project’s appropriate Java version.