Home  >  Article  >  Java  >  Why Does My Maven Build Fail with \'java.lang.IllegalArgumentException\' When Compiling Java 10/11?

Why Does My Maven Build Fail with \'java.lang.IllegalArgumentException\' When Compiling Java 10/11?

Linda Hamilton
Linda HamiltonOriginal
2024-11-21 02:45:11618browse

Why Does My Maven Build Fail with

Unable to Compile Java 10/11 Project with Maven

A common issue encountered when attempting to compile Java 10 or 11 projects with Maven is a failure with the error message "java.lang.IllegalArgumentException". This error occurs due to limitations in the Maven compiler plugin.

Fix

To resolve this issue, the following steps can be taken:

  1. Configure the Plugin Version: Use the maven-compiler-plugin version 3.8.0 or later, which supports Java 10 and 11. By default, the plugin compiles code using Java version 1.6, so it needs to be explicitly specified.
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
</plugin>
  1. Specify the Release: In the plugin configuration, set the "release" property to the desired Java version, either 9, 10, or 11.
<configuration>
    <release>11</release>
</configuration>

Note: The default source/target levels have been updated to 1.6 with the new plugin version.

Extended Support for JDK 12

The same maven-compiler-plugin version 3.8.0 can also be used to compile code against JDK 12. Refer to the Maven documentation for details on compiling and executing Java preview features with Maven.

The above is the detailed content of Why Does My Maven Build Fail with \'java.lang.IllegalArgumentException\' When Compiling Java 10/11?. For more information, please follow other related articles on the PHP Chinese website!

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