Home > Java > javaTutorial > body text

Why Does My Maven Java 10/11 Project Fail to Compile, and How Can I Fix It?

Linda Hamilton
Release: 2024-11-22 07:55:10
Original
398 people have browsed it

Why Does My Maven Java 10/11 Project Fail to Compile, and How Can I Fix It?

Unable to Compile Simple Java 10/Java 11 Project with Maven

This issue arises when attempting to build a project using Java 10 or 11 in conjunction with Maven. Despite specifying a release value of "10" for the maven-compiler-plugin's configuration, the build fails.

Cause:

The failure is caused by an incompatibility between the Maven compiler plugin and the Java version used during compilation. The plugin used in the provided example (3.7.0) does not support explicitly specifying a Java release version.

Solution:

To resolve this issue, it is necessary to upgrade the maven-compiler-plugin to version 3.8.0. This upgraded plugin supports specifying a release value for Java versions 9, 10, and 11.

Updated pom.xml:

...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <release>10</release>
    </configuration>
</plugin>
...
Copy after login

Important Note:

  • With version 3.8.0 of the maven-compiler-plugin, the default source/target settings have changed from 1.5 to 1.6.
  • The upgraded plugin (version 3.8.0) supports compiling code against JDK 12 as well.

The above is the detailed content of Why Does My Maven Java 10/11 Project Fail to Compile, and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template