Site icon TestingDocs.com

Specify Java version in a Maven Project.

Introduction

In this post, we will learn how to specify the Java version in the Maven pom.xml file. This is very useful when you are upgrading the Maven project to higher version of Java. Fixing errors during building Maven project. Example of one such error shown.

Sample Error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Sample: Compilation failure: Compilation failure:

[ERROR] Source option 5 is no longer supported. Use 7 or later.

[ERROR] Target option 5 is no longer supported. Use 7 or later.

Specifying Java version in POM

Configure the Maven compiler plugin in the POM.xml

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

Screenshot:

 

We can cross check the settings in the Project settings window >> Java Compiler setting.

 

 

Maven Tutorials on this website can be found at:
https://www.testingdocs.com/apache-maven-tutorial/

 

Exit mobile version