【发布时间】:2021-11-12 18:03:02
【问题描述】:
我正在将我的 Maven 构建的 Java 8 应用升级到 Java 11。在我的 POM 中我指定:
<properties>
<java.version>1.11</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
当我使用正常的 Maven 构建调用构建我的应用程序时:
mvn verify -Plocal -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
我明白了:
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< example.com:myapp-svc >------------------------
[INFO] Building myapp-svc 1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-checkstyle-plugin:3.1.2:check (validate) @ myapp-svc ---
[WARNING] Old version of checkstyle detected. Consider updating to >= v8.30
[WARNING] For more information see: https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html
[INFO] Starting audit...
Audit done.
[INFO] You have 0 Checkstyle violations.
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.7:prepare-agent (default) @ myapp-svc ---
[INFO] argLine set to -javaagent:/Users/myuser/.m2/repository/org/jacoco/org.jacoco.agent/0.8.7/org.jacoco.agent-0.8.7-runtime.jar=destfile=/Users/myuser/workspace/myapp-svc/target/jacoco.exec
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ myapp-svc ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 6 resources
[INFO] Copying 154 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ myapp-svc ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 456 source files to /Users/myuser/workspace/myapp-svc/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.076 s
[INFO] Finished at: 2021-11-12T12:52:52-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project myapp-svc: Fatal error compiling: error: invalid target release: 1.11 -> [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
所以看起来maven-compiler-plugin:3.8.1 插件与Java 11 不兼容。问题是,我没有直接在我的POM 中的任何地方指定该插件。因此,某处正在拉动它并使用它,我的猜测是我必须更新 那个 的东西,以便它引入 是的maven-compiler-plugin 版本 em> 与 Java 11 兼容。
那么我怎么知道是什么在拉动它并使用它呢?或者,如果这不是正在发生的事情,那是什么以及如何解决?
【问题讨论】:
-
去掉“1”。从Java版本。改为:
<java.version>11</java.version> -
哦,哇,谢谢@BasilBourque (+1)。这行得通,但是我很好奇,以前那个值是
<java.version>1.8</java.version>。那么为什么 不会 是 Java 11 的 1.11 呢?同样本着“授人以渔”的精神,您怎么知道正确的值是“11”而不是“1.11”?再次感谢! -
您可能会在 Java JEP 中找到记录和解释的 Java 版本编号更改。
-
请发布并接受对您问题的回答,准确说明您为解决问题所做的工作。并链接到那个 JEP,如果你找到的话。
-
因为您很感兴趣,所以您应该像我建议的那样花更多的精力来阅读 Java JEP。只需在 JEP 标题中搜索“版本”一词即可将您带到JEP 223: New Version-String Scheme。通过学习JEP,你可以学到很多关于Java的精彩,比如records。
标签: java maven maven-plugin java-11