Intellij maven project Fatal error compiling: invalid flag: --release

后端 未结 4 1031
长情又很酷
长情又很酷 2020-12-16 09:20

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         


        
相关标签:
4条回答
  • 2020-12-16 09:26

    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>
    
    0 讨论(0)
  • 2020-12-16 09:28

    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

    0 讨论(0)
  • 2020-12-16 09:32

    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

    0 讨论(0)
  • 2020-12-16 09:39

    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>
    
    0 讨论(0)
提交回复
热议问题