javaspring-bootintellij-ideapom.xmlspring-boot-maven-plugin

Apache Maven plugins 3.11.0 Compile Issue


WHILE TRYING TO RUN MY SPRING APPLICATION WITH THE FOLLOWING pom.xml WITH JAVA 17 INSTALLED IN MY SYSTEM I AM FACED WITH THE FOLLOWING ERROR WHILE RUNNING mvn clean install I GET THE FOLLOWING ERROR IN MY IntelliJ TERMINAL:

TERMINAL LOGS

Latitude-3420:~/TelegramWeb$ java -version
openjdk version "17.0.9" 2023-10-17
OpenJDK Runtime Environment (build 17.0.9+9-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 17.0.9+9-Ubuntu-120.04, mixed mode, sharing)
Latitude-3420:~TelegramWeb$ mvn clean install 
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< com.example:TelegramWeb >-----------------------
[INFO] Building TelegramWeb 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.3.2:clean (default-clean) @ TelegramWeb ---
[INFO] Deleting /home/TelegramWeb/target
[INFO] 
[INFO] --- maven-resources-plugin:3.3.1:resources (default-resources) @ TelegramWeb ---
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO] 
[INFO] --- maven-compiler-plugin:3.11.0:compile (default-compile) @ TelegramWeb ---
[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:  0.824 s
[INFO] Finished at: 2023-12-18T04:39:45+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project TelegramWeb: Fatal error compiling: invalid flag: --release -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

GIVEN BELOW IS THE POM.XML I AM TRYING TO 'mvn clean install'.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.0</version>
        <relativePath/>
    </parent>

    <groupId>com.example</groupId>
    <artifactId>TelegramWeb</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>TelegramWeb</name>

    <properties>
        <java.version>17</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

I also added the following:

    <properties>
        <java.version>17</java.version>
        <maven.compiler.release>17</maven.compiler.release>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

AND

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <release>17</release>
                </configuration>
            </plugin>
        </plugins>
    </build>

But the error persists. Please help.


Solution

  • Terminal has its own environment.In IntelliJ, execute mvn -v at the command prompt to view the version of Java used by your current Maven. I copied your pom.xml file to execute the same error as you. After that, I executed the mvn -v command and found that Maven uses Java 1.8.I found that I set a JAVA_HOME and a JAVA_HOME_17 in the environment variables.I deleted the 1.8 version and only left the 17 version. After restarting IntelliJ, executing mvn -v in the Terminal, it became 17.0.9. Then I executed mvn clean install and the result was BUILD SUCCESS.