致命错误编译:不支持使用 IntelliJ IDEA 和 Maven 发布版本 10.0.1。

huangapple go评论73阅读模式
英文:

Fatal error compiling: release version 10.0.1 not supported using IntelliJ IDEA and Maven

问题

在 macOS Catalina 10.15.4 上,我安装了 jdk-10.0.1。

当我打开终端并输入:

echo $JAVA_HOME

标准输出:

/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home

Java 版本:

java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)

mvn -version
mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/pnwlover/maven/apache-maven-3.6.3
Java version: 10.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.4", arch: "x86_64", family: "mac"

创建一个示例的 Maven 项目并将 JUnit 5 设置为依赖:

<?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.sample</groupId>
    <artifactId>Calculator</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>10.0.1</java.version>
        <maven.compiler.source>10.0.1</maven.compiler.source>
        <maven.compiler.target>10.0.1</maven.compiler.target>
        <junit-jupiter.version>5.3.2</junit-jupiter.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- junit 5 -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit-jupiter.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>10.0.1</release>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.ow2.asm</groupId>
                        <artifactId>asm</artifactId>
                        <version>6.2</version> 
                    </dependency>
                </dependencies>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
                <dependencies>
                    <dependency>
                        <groupId>org.ow2.asm</groupId>
                        <artifactId>asm</artifactId>
                        <version>6.1.1</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

</project>

Calculator 类:

package com.sample;

public class Calculator {

    public static int add(int a, int b) {
        return a + b;
    }
}

JUnit 5 测试:

package com.sample;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class CalculatorTest {

    @Test
    public void add() {
        assertEquals(5, Calculator.add(2, 2));
    }

}

当我通过终端或 IntelliJ IDEA Ultimate Edition 2019.3(作为 Maven 运行配置 mvn test)运行它时,我会得到以下错误:

[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< com.sample:Calculator >----------------------
[INFO] Building Calculator 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Calculator ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ Calculator ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /Users/pnwlover/Calculator/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.655 s
[INFO] Finished at: 2020-04-04T16:57:35-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project Calculator: Fatal error compiling: release version 10.0.1 not supported -> [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
英文:

On macOS Catalina 10.15.4, I have jdk-10.0.1 installed.

When I go to the Terminal and type in:

echo $JAVA_HOME

stdout:

/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home

Java version:

java -version
java version &quot;10.0.1&quot; 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)

mvn -version
mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/pnwlover/maven/apache-maven-3.6.3
Java version: 10.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: &quot;mac os x&quot;, version: &quot;10.15.4&quot;, arch: &quot;x86_64&quot;, family: &quot;mac&quot;

Created a sample maven project and set JUnit 5 as a dependency:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;com.sample&lt;/groupId&gt;
&lt;artifactId&gt;Calculator&lt;/artifactId&gt;
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;properties&gt;
&lt;java.version&gt;10.0.1&lt;/java.version&gt;
&lt;maven.compiler.source&gt;10.0.1&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;10.0.1&lt;/maven.compiler.target&gt;
&lt;junit-jupiter.version&gt;5.3.2&lt;/junit-jupiter.version&gt;
&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;!-- junit 5 --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
&lt;artifactId&gt;junit-jupiter-engine&lt;/artifactId&gt;
&lt;version&gt;${junit-jupiter.version}&lt;/version&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;version&gt;3.8.0&lt;/version&gt;
&lt;configuration&gt;
&lt;release&gt;10.0.1&lt;/release&gt;
&lt;/configuration&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.ow2.asm&lt;/groupId&gt;
&lt;artifactId&gt;asm&lt;/artifactId&gt;
&lt;version&gt;6.2&lt;/version&gt; 
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
&lt;version&gt;2.22.0&lt;/version&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.ow2.asm&lt;/groupId&gt;
&lt;artifactId&gt;asm&lt;/artifactId&gt;
&lt;version&gt;6.1.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/project&gt;

Calculator class:

package com.sample;
public class Calculator {
public static int add(int a, int b) {
return a + b;
}
}

JUnit 5 test:

package com.sample;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class CalculatorTest {
@Test
public void add() {
assertEquals(5, Calculator.add(2, 2));
}
}

When I run it via Terminal or IntelliJ IDEA Ultimate Edition 2019.3 (as a Maven run config mvn test), I get the following error:

[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------&lt; com.sample:Calculator &gt;----------------------
[INFO] Building Calculator 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Calculator ---
[INFO] Using &#39;UTF-8&#39; encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ Calculator ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /Users/pnwlover/Calculator/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.655 s
[INFO] Finished at: 2020-04-04T16:57:35-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project Calculator: Fatal error compiling: release version 10.0.1 not supported -&gt; [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

答案1

得分: 1

Java源/目标版本指定为10.0.1不受支持。您应该仅使用主要版本,如10

&lt;java.version&gt;10&lt;/java.version&gt;
&lt;maven.compiler.source&gt;10&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;10&lt;/maven.compiler.target&gt;
&lt;configuration&gt;
&lt;release&gt;10&lt;/release&gt;
&lt;/configuration&gt;

在IntelliJ IDEA中打开pom.xml文件,按下<kbd>Ctrl</kbd>+<kbd>R</kbd>(在macOS上为<kbd>Alt</kbd>/<kbd>Option</kbd>+<kbd>R</kbd>)以执行替换操作,将10.0.1输入搜索字段,按<kbd>Tab</kbd>,在替换字段中输入10,按<kbd>Alt</kbd>+<kbd>A</kbd>以执行全部替换

英文:

Java source/target version specified as 10.0.1 is not supported. You should use the major version only like 10 instead:

&lt;java.version&gt;10&lt;/java.version&gt;
&lt;maven.compiler.source&gt;10&lt;/maven.compiler.source&gt;
&lt;maven.compiler.target&gt;10&lt;/maven.compiler.target&gt;
&lt;configuration&gt;
&lt;release&gt;10&lt;/release&gt;
&lt;/configuration&gt;

In IntelliJ IDEA open pom.xml file, press <kbd>Ctrl</kbd>+<kbd>R</kbd> (<kbd>Alt</kbd>/<kbd>Option</kbd>+<kbd>R</kbd> on macOS) for Replace action, type 10.0.1 in the search field, <kbd>Tab</kbd>, type 10 in the replace field, <kbd>Alt</kbd>+<kbd>A</kbd> for Replace All.

huangapple
  • 本文由 发表于 2020年4月5日 08:09:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/61036437.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定