admin管理员组

文章数量:1299997

I have the following simple POM, with only one .java file in src/main/java:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=".0.0"
         xmlns:xsi=";
         xsi:schemaLocation=".0.0 .0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <mavenpiler.release>21</mavenpiler.release>
    </properties>
</project>

When I run mvn compile I get the following error:

[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Source option 5 is no longer supported. Use 8 or later.
[ERROR] Target option 5 is no longer supported. Use 8 or later.

Compilation works if I provide mavenpiler.source and mavenpiler.target.

My understanding is that mavenpiler.release is supposed to pass the --release to the javac. However, the --release supersedes, and is not compatible with, --source and --target according to official javac documentations.

Which part did I get wrong?

The output of mvn -v is the following:

Apache Maven 3.8.7
Maven home: /usr/share/maven
Java version: 21.0.6, vendor: Ubuntu, runtime: /usr/lib/jvm/java-21-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.15.167.4-microsoft-standard-wsl2", arch: "amd64", family: "unix"

Answering Comments

Since one comment mentioned it, this question is not the same as this one.

  • I know the solution to my problem, what I need is an explanation.
  • My question has nothing to do with Eclipse or any IDE.
  • My question is about mavenpiler.release and how does it apply to compilation flags.

I originally wanted my question to be brief, so I didn't state every thing I tried. Providing maven-compiler-plugin latest version (3.13.0) didn't work. The error message however is different:

Fatal error compiling: error: release version 9 not supported -> [Help 1]

I tried with an old (9) and a new (21) versions of Java. I get the same result when I provide configuration/release.

    <build>
        <plugins>
            <plugin>
                <groupId>.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <release>9</release>
                </configuration>
            </plugin>
        </plugins>
    </build>

本文标签: javaSimple Maven project with mavencompilerrelease not workingStack Overflow