我看到这个问题的很多答案,但它们对我不起作用。我在我的 PC 上安装了 Visual Studio Code、最新版本的 Java 和 Maven,我能够在 PC 上使用 Maven 成功构建我的应用程序。然后,我在我的 Mac 上执行了相同的步骤,但出现了这个错误。
全新版本的 Macos、Visual Studio Code、Maven 和 Java。就像其他人所说的那样,我将这些行添加到我的 pom.xml 文件的属性部分:
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
仍然得到同样的错误。这是 mvn build 的相关输出:
alberts-mbp:com.versabuilt.rushmore.process albertyoungwerth$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ---------< com.versabuilt.rushmore.process:VersaBuiltProcess >----------
[INFO] Building VersaBuilt Process 0.2.18
[INFO] -------------------------------[ bundle ]-------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ VersaBuiltProcess ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.0:compile (default-compile) @ VersaBuiltProcess ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 10 source files to /Users/albertyoungwerth/rushmore/com.versabuilt.rushmore.process/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Source option 6 is no longer supported. Use 7 or later.
[ERROR] Target option 6 is no longer supported. Use 7 or later.
[INFO] 2 errors
我也重新启动了 Visual Studio Code 无济于事。
原文由 Al Youngwerth 发布,翻译遵循 CC BY-SA 4.0 许可协议
我使用的最后一个构建系统叫做 make,所以我已经有一段时间没有调试构建过程了。我也不记得 make dumping 62Kb 的调试输出…
任何人,搜索关键字“source”(线索是我应该添加的标签之一)让我在 maven 调试输出中找到这个:
[调试] (f) 来源 = 1.6
啊哈!源编译器版本没有像我在原始问题中要求的那样更改!我敢打赌,行家们改变了 xml 标签的位置!果然,在 pom.xml 文件中搜索 1.6 我发现了这个:
我将源和目标标签值更改为 1.8,它起作用了!我还尝试删除构建插件范围中的源和目标标记,并将 maven.compiler.source/target 值保留为 1.8,这也有效。
故事的寓意是,当心 pom.xml 文件中的额外源或目标标记!