118

I am trying to start with Spring-boot, Maven in Intellij Please help me I am getting the error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project spring-rest: 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
Process finished with exit code 1

My pom.xml is:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
       <modelVersion>4.0.0</modelVersion>

       <groupId>com.example</groupId>
       <artifactId>spring-rest</artifactId>
       <version>3.1.3.RELEASE</version>
       <packaging>war</packaging>

       <name>spring-rest</name>
       <description>Demo project for Spring Boot</description>

       <parent>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-parent</artifactId>
           <version>2.0.0.RELEASE</version>
           <relativePath/> <!-- lookup parent from repository -->
       </parent>

       <properties>
           <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
           <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
           <java.version>1.8</java.version>
       </properties>

       <dependencies>

           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-security</artifactId>
               <version>2.0.0.RELEASE</version>
           </dependency>

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

           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-data-jpa</artifactId>
           </dependency>
           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-web</artifactId>
           </dependency>

           <dependency>
               <groupId>org.hibernate.javax.persistence</groupId>
               <artifactId>hibernate-jpa-2.1-api</artifactId>
               <version>RELEASE</version>
           </dependency>


           <dependency>
               <groupId>mysql</groupId>
               <artifactId>mysql-connector-java</artifactId>
               <scope>runtime</scope>
           </dependency>
           <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-test</artifactId>
               <scope>test</scope>
           </dependency>
       </dependencies>

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

               <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-compiler-plugin</artifactId>
                   <version>3.7.0</version>
                   <configuration>
                       <source>1.8</source>
                       <target>1.8</target>
                       <release>8</release>
                       <verbose>true</verbose>
                   </configuration>
               </plugin>
           </plugins>
       </build>

   </project>
Matteo Baldi
  • 5,613
  • 10
  • 39
  • 51
Aminul
  • 1,427
  • 2
  • 8
  • 16

11 Answers11

120

In your pom.xml file, simply remove the tag <release>8</release> from your maven-compiler-plugin configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.7.0</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <verbose>true</verbose>
    </configuration>
</plugin>
Matteo Baldi
  • 5,613
  • 10
  • 39
  • 51
  • 14
    Worked for me - thanks - just to add a reason - looks like "release" added for Java 9 backwards compatibility https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#release. Doesn't quite handle forwards compatability though. – Dazed Jun 14 '18 at 09:09
  • 13
    If one has multiple java versions installed: verify you are running maven with java 9+ version: `mvn --version`. Also ensure your IDE uses proper JDK version. – radistao Dec 02 '19 at 13:59
  • 2
    right ... the minimum requirement of the env. setup for using "--release" option is: Maven: 3.6.0 ; JDK: 9+ – garykwwong Apr 19 '20 at 03:41
  • 1
    @radistao Thanks, I had newest maven but java 8 in $JAVA_HOME added to system path. I hanged it to 11 and now 'release' works. – luke Sep 05 '20 at 10:33
  • 3
    Just for the reference, once changed the JAVA_HOME one must restart their intellij. – gaurav kumar Sep 29 '20 at 21:34
  • please navigate to @Krisna Vedula answer first. This one _fixes_ the problem for jdk8 and less, but without knowing the correct cause. It just might be, that your pom.xml is completely correct and you're just using incorret JAVA_HOME. – Martin Mucha Jan 14 '23 at 09:38
40

This has to do with the version of JDK running on your system. As per the documentation for maven-compiler-plugin, the release flag is supported since 1.9, and thus has to be commented/removed from the POM if you are using prior (1.8 and below) versions of JDK.

Check Maven documentation for release tag for maven-compiler-plugin here

Krishna Vedula
  • 1,643
  • 1
  • 27
  • 31
  • 5
    I ran into this problem, and I'd forgotten to change the JAVA_HOME environment variable to point at my java 11 JDK. (`export JAVA_HOME=$(/usr/libexec/java_home -v11)` ) – Andrew Rueckert Jun 24 '20 at 00:17
16

I faced this problem too, check your JAVA_HOME environment variable. I was setting the value of release to 11 as I am using JAVA 11. My System JAVA_HOME was set for java 8, After adding the JAVA_HOME user environment variable to the java 11 path this got resolved.

Raulster24
  • 403
  • 3
  • 14
14

open terminal to check that Maven using correct version of Java

run: mvn -v

If you will see an old Java version, that might be the problem.

Being on Linux, I suggest removing Maven, e.g. using Fedora package manager dnf remove maven or check your PATH for maven.

Download one from here: https://maven.apache.org/download.cgi

Extract downloaded to your home path, e.g. ~/maven.

Add/Edit ~/maven/bin to your PATH

Reapply .bash_profile (or re-login)

Run mvn -v

Now you should see a correct Java version in the output

izy
  • 1,085
  • 14
  • 18
  • In my case, I was using both jenv and sdkman to manage java versions. jenv java version was set correctly to jre 17 but sdkman was still on jre8. Once I switched to jre17 through sdkman, the "invalid release" error went away. – user674669 Aug 16 '23 at 07:38
4

An alternative approach is to directly set the compiler flags inside your properties tag instead of using the <configuration> tag of the compiler plugin:

<properties>
       <maven.compiler.source>8</maven.compiler.source>
       <maven.compiler.target>8</maven.compiler.target>
 <!--  Use the release flag only if you are using Java 9+  -->
 <!--  <maven.compiler.release>8</maven.compiler.release>  -->
       <!-- verbose is useful for debugging purposes -->
       <maven.compiler.verbose>true</maven.compiler.verbose> 
</properties>

As stated in the official page:

https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

Domenico
  • 1,331
  • 18
  • 22
4

I was getting this error with Java v8, then resolved the issue by updating to Java v11, updating JAVA_HOME, and updating my IntelliJ SDK settings to use the new jdk.

Cyro
  • 85
  • 5
2

This is mostly because of the java version mismatch. Managing more than one java version for projects can be painful.

I am working simultaneously on projects asking for different versions of java and have been using jenv for switching the java versions.

More details here

2

Use mvn -v in cmd to find the java version.

In your case, you have declared java 8 in pom.xml, use the same in the JAVA_HOME of environment variables, this will resolve the issue.

0
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile (default-testCompile) on project selenium-for-beginners: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile failed: multiple points -> [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/PluginExecutionException

When trying to do a Selenium maven beginner project if you are running into this trouble/issue. Please try to change the maven plugin in the pom.xml file. Use Plugin for "Compile Using the --release javac option (JDK 9+)". This should work.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
0

Set the $MAVEN_HOME and JAVA_HOME in environment Properties

  1. Check the maven version ( C:>mvn -version )

  2. Check the Java Version ( C:>java -version )

Add the below code snip in pom.xml file and change the version number of maven

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.7.0</version> // replace the maven version number 
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <verbose>true</verbose>
    </configuration>
</plugin>
Lova Chittumuri
  • 2,994
  • 1
  • 30
  • 33
-5

This configuration worked for me, for java 11. (IntelliJ version 2019.1) java.version is 11, declared in the properties part of the pom.xml. Maven version should be 3.6 or higher.

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <fork>false</fork>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <encoding>UTF-8</encoding>
                <compilerArgs>
                    <arg>-parameters</arg>
                </compilerArgs>
                <release>${java.version}</release>
                <forceJavacCompilerUse>true</forceJavacCompilerUse>
            </configuration>
            <executions>
                <!-- Replacing default-compile as it is treated specially by maven -->
                <execution>
                    <id>default-compile</id>
                    <phase>none</phase>
                </execution>
                <!-- Replacing default-testCompile as it is treated specially by maven -->
                <execution>
                    <id>default-testCompile</id>
                    <phase>none</phase>
                </execution>
                <execution>
                    <id>java-compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>java-test-compile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
    </plugin>
Vlad. V
  • 3
  • 3
gorjanz
  • 1,954
  • 2
  • 18
  • 13