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 target options to the maven-compiler-plugin, for example:

1
2
3
4
5
6
7
8
9
10
11
12
13
<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 target to the project’s appropriate Java version.

Share Comments