spring boot - Java Springboot project compile fails with "Fatal error compiling: invalid flag: --release" on M

I am trying to use Java 8 and Maven 3.5.4 to build a project. I have NOT set any flags in the pom.xml.

I am trying to use Java 8 and Maven 3.5.4 to build a project. I have NOT set any flags in the pom.xml. I'm still getting a Fatal error compiling: invalid flag: --release error when I try to run mvn install or mvn compile.

Google says Java 8 doesnt support the release flag, so thats the first thing I changed.

Things I have already tried that have failed:

  1. Installed Java versions 11 and 17 and updated the same in pom.xml and in local environment.
  2. Wrote an extremely simple "hello world" Spring Boot program.

The build still fails with the same error.

I am unsure how to proceed. This seems more like a configuration issue rather than a code issue. Should I try different versions of Maven and Maven plugin? Would it be worth investigating different build tools, like Gradle or Ant?

Any help would be appreciated!!

Output of mvn -v:

Apache Maven 3.5.4 (Red Hat 3.5.4-5)
Maven home: /usr/share/maven
Java version: 1.8.0_442, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.442.b06-2.el8.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-553.40.1.el8_10.x86_64", arch: "amd64", family: "unix"

Output of alternatives --config java

There are 3 programs which provide 'java'.
  Selection    Command
-----------------------------------------------
   1           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.25.0.9-2.el8.x86_64/bin/java)
*  2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.442.b06-2.el8.x86_64/jre/bin/java)
 + 3           java-17-openjdk.x86_64 (/usr/lib/jvm/java-17-openjdk-17.0.14.0.7-3.el8.x86_64/bin/java)
Enter to keep the current selection[+], or type selection number:

Snippet of output of mvn compile:

[INFO] --- maven-compiler-plugin:3.11.0:compile (default-compile) @ myProject ---
[INFO] Changes detected - recompiling the module! :source
[INFO] Compiling 1 source file with javac [debug release 17] to target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.242 s
[INFO] Finished at: 2025-03-07T10:00:29Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal .apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project myProject: Fatal error compiling: invalid flag: --release -> [Help 1]

As you can see, Java 17 is enabled and is being used for compiling.

Java 17 version of pom.xml (this Spring Boot project was generated using Spring Initializr):

<?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>
    <parent>
        <groupId>.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.my.project</groupId>
    <artifactId>myproject</artifactId>
    <version>0.1</version>
    <packaging>war</packaging>
    <name>myProject</name>
    <description>My Project</description>
    <properties>
        <java.version>17</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>3.1.0</version>
            </plugin>
        </plugins>
    </build>

</project>

The Java 8 version is almost exactly the same, except it does not have <version>3.1.0</version> in the <artifactId>spring-boot-maven-plugin</artifactId> tag, and it has the <java.version>8</java.version> in the <properties> tag.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744933940a4601904.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信