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

huangapple 未分类评论44阅读模式
英文:

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

问题

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

当我打开终端并输入:

  1. echo $JAVA_HOME

标准输出:

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

Java 版本:

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

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

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

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <groupId>com.sample</groupId>
  7. <artifactId>Calculator</artifactId>
  8. <version>1.0-SNAPSHOT</version>
  9. <properties>
  10. <java.version>10.0.1</java.version>
  11. <maven.compiler.source>10.0.1</maven.compiler.source>
  12. <maven.compiler.target>10.0.1</maven.compiler.target>
  13. <junit-jupiter.version>5.3.2</junit-jupiter.version>
  14. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  15. </properties>
  16. <dependencies>
  17. <!-- junit 5 -->
  18. <dependency>
  19. <groupId>org.junit.jupiter</groupId>
  20. <artifactId>junit-jupiter-engine</artifactId>
  21. <version>${junit-jupiter.version}</version>
  22. <scope>test</scope>
  23. </dependency>
  24. </dependencies>
  25. <build>
  26. <plugins>
  27. <plugin>
  28. <groupId>org.apache.maven.plugins</groupId>
  29. <artifactId>maven-compiler-plugin</artifactId>
  30. <version>3.8.0</version>
  31. <configuration>
  32. <release>10.0.1</release>
  33. </configuration>
  34. <dependencies>
  35. <dependency>
  36. <groupId>org.ow2.asm</groupId>
  37. <artifactId>asm</artifactId>
  38. <version>6.2</version>
  39. </dependency>
  40. </dependencies>
  41. </plugin>
  42. <plugin>
  43. <groupId>org.apache.maven.plugins</groupId>
  44. <artifactId>maven-surefire-plugin</artifactId>
  45. <version>2.22.0</version>
  46. <dependencies>
  47. <dependency>
  48. <groupId>org.ow2.asm</groupId>
  49. <artifactId>asm</artifactId>
  50. <version>6.1.1</version>
  51. </dependency>
  52. </dependencies>
  53. </plugin>
  54. </plugins>
  55. </build>
  56. </project>

Calculator 类:

  1. package com.sample;
  2. public class Calculator {
  3. public static int add(int a, int b) {
  4. return a + b;
  5. }
  6. }

JUnit 5 测试:

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

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

  1. [INFO] Scanning for projects...
  2. [INFO]
  3. [INFO] ---------------------< com.sample:Calculator >----------------------
  4. [INFO] Building Calculator 1.0-SNAPSHOT
  5. [INFO] --------------------------------[ jar ]---------------------------------
  6. [INFO]
  7. [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Calculator ---
  8. [INFO] Using 'UTF-8' encoding to copy filtered resources.
  9. [INFO] Copying 0 resource
  10. [INFO]
  11. [INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ Calculator ---
  12. [INFO] Changes detected - recompiling the module!
  13. [INFO] Compiling 2 source files to /Users/pnwlover/Calculator/target/classes
  14. [INFO] ------------------------------------------------------------------------
  15. [INFO] BUILD FAILURE
  16. [INFO] ------------------------------------------------------------------------
  17. [INFO] Total time: 0.655 s
  18. [INFO] Finished at: 2020-04-04T16:57:35-07:00
  19. [INFO] ------------------------------------------------------------------------
  20. [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]
  21. [ERROR]
  22. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  23. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  24. [ERROR]
  25. [ERROR] For more information about the errors and possible solutions, please read the following articles:
  26. [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:

  1. echo $JAVA_HOME

stdout:

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

Java version:

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

  1. mvn -version
  1. mvn -version
  2. Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
  3. Maven home: /Users/pnwlover/maven/apache-maven-3.6.3
  4. Java version: 10.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
  5. Default locale: en_US, platform encoding: UTF-8
  6. 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:

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  2. &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
  3. xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  4. xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  5. &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  6. &lt;groupId&gt;com.sample&lt;/groupId&gt;
  7. &lt;artifactId&gt;Calculator&lt;/artifactId&gt;
  8. &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  9. &lt;properties&gt;
  10. &lt;java.version&gt;10.0.1&lt;/java.version&gt;
  11. &lt;maven.compiler.source&gt;10.0.1&lt;/maven.compiler.source&gt;
  12. &lt;maven.compiler.target&gt;10.0.1&lt;/maven.compiler.target&gt;
  13. &lt;junit-jupiter.version&gt;5.3.2&lt;/junit-jupiter.version&gt;
  14. &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  15. &lt;/properties&gt;
  16. &lt;dependencies&gt;
  17. &lt;!-- junit 5 --&gt;
  18. &lt;dependency&gt;
  19. &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
  20. &lt;artifactId&gt;junit-jupiter-engine&lt;/artifactId&gt;
  21. &lt;version&gt;${junit-jupiter.version}&lt;/version&gt;
  22. &lt;scope&gt;test&lt;/scope&gt;
  23. &lt;/dependency&gt;
  24. &lt;/dependencies&gt;
  25. &lt;build&gt;
  26. &lt;plugins&gt;
  27. &lt;plugin&gt;
  28. &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  29. &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
  30. &lt;version&gt;3.8.0&lt;/version&gt;
  31. &lt;configuration&gt;
  32. &lt;release&gt;10.0.1&lt;/release&gt;
  33. &lt;/configuration&gt;
  34. &lt;dependencies&gt;
  35. &lt;dependency&gt;
  36. &lt;groupId&gt;org.ow2.asm&lt;/groupId&gt;
  37. &lt;artifactId&gt;asm&lt;/artifactId&gt;
  38. &lt;version&gt;6.2&lt;/version&gt;
  39. &lt;/dependency&gt;
  40. &lt;/dependencies&gt;
  41. &lt;/plugin&gt;
  42. &lt;plugin&gt;
  43. &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  44. &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
  45. &lt;version&gt;2.22.0&lt;/version&gt;
  46. &lt;dependencies&gt;
  47. &lt;dependency&gt;
  48. &lt;groupId&gt;org.ow2.asm&lt;/groupId&gt;
  49. &lt;artifactId&gt;asm&lt;/artifactId&gt;
  50. &lt;version&gt;6.1.1&lt;/version&gt;
  51. &lt;/dependency&gt;
  52. &lt;/dependencies&gt;
  53. &lt;/plugin&gt;
  54. &lt;/plugins&gt;
  55. &lt;/build&gt;
  56. &lt;/project&gt;

Calculator class:

  1. package com.sample;
  2. public class Calculator {
  3. public static int add(int a, int b) {
  4. return a + b;
  5. }
  6. }

JUnit 5 test:

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

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:

  1. [INFO] Scanning for projects...
  2. [INFO]
  3. [INFO] ---------------------&lt; com.sample:Calculator &gt;----------------------
  4. [INFO] Building Calculator 1.0-SNAPSHOT
  5. [INFO] --------------------------------[ jar ]---------------------------------
  6. [INFO]
  7. [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Calculator ---
  8. [INFO] Using &#39;UTF-8&#39; encoding to copy filtered resources.
  9. [INFO] Copying 0 resource
  10. [INFO]
  11. [INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ Calculator ---
  12. [INFO] Changes detected - recompiling the module!
  13. [INFO] Compiling 2 source files to /Users/pnwlover/Calculator/target/classes
  14. [INFO] ------------------------------------------------------------------------
  15. [INFO] BUILD FAILURE
  16. [INFO] ------------------------------------------------------------------------
  17. [INFO] Total time: 0.655 s
  18. [INFO] Finished at: 2020-04-04T16:57:35-07:00
  19. [INFO] ------------------------------------------------------------------------
  20. [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]
  21. [ERROR]
  22. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  23. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  24. [ERROR]
  25. [ERROR] For more information about the errors and possible solutions, please read the following articles:
  26. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

答案1

得分: 1

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

  1. &lt;java.version&gt;10&lt;/java.version&gt;
  2. &lt;maven.compiler.source&gt;10&lt;/maven.compiler.source&gt;
  3. &lt;maven.compiler.target&gt;10&lt;/maven.compiler.target&gt;
  1. &lt;configuration&gt;
  2. &lt;release&gt;10&lt;/release&gt;
  3. &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:

  1. &lt;java.version&gt;10&lt;/java.version&gt;
  2. &lt;maven.compiler.source&gt;10&lt;/maven.compiler.source&gt;
  3. &lt;maven.compiler.target&gt;10&lt;/maven.compiler.target&gt;
  1. &lt;configuration&gt;
  2. &lt;release&gt;10&lt;/release&gt;
  3. &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://java.coder-hub.com/61036437.html
匿名

发表评论

匿名网友

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

确定