【问题标题】:Another Maven "Source option 6 is no longer supported. Use 7 or later."另一个 Maven “不再支持源选项 6。使用 7 或更高版本。”
【发布时间】:2020-09-03 17:50:52
【问题描述】:

我看到了很多关于这个问题的答案,但它们对我不起作用。我在我的 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,但无济于事。

【问题讨论】:

  • 您安装了哪个版本的 Java?我猜测 Java 6。但我不知道。
  • 在你的电脑上查看java -version,查看VS代码中的JVM配置。
  • 在您的问题中包含 mvnjavac 的版本是值得的 - 只是说新版本没有帮助。如果您可以提供指向示例项目的链接,也很有用。
  • java版本“14.0.1”2020-04-14
  • Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven 主页:/Applications/apache-maven-3.6.3 Java 版本:14.0.1,供应商:Oracle Corporation,运行时:/Library/Java/JavaVirtualMachines/ jdk-14.0.1.jdk/Contents/Home

标签: java macos maven visual-studio-code


【解决方案1】:

我使用的最后一个构建系统称为 make,所以我已经有一段时间没有调试构建过程了。我也不记得要转储 62Kb 的调试输出...

任何人,搜索关键字“source”(线索是我应该添加的标签之一)让我在 maven 调试输出中找到了这个:

[调试] (f) 源 = 1.6

啊哈!源编译器版本没有像我在原始问题中的编辑所要求的那样改变!我敢打赌,maven 人改变了 xml 标签的位置!果然,在pom.xml文件中搜索1.6我发现了这个:

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>

我将源标签值和目标标签值更改为 1.8,它成功了!我还尝试删除构建插件范围中的源和目标标记,并将 maven.compiler.source/target 值设置为 1.8,这也有效。

故事的寓意,小心你的 pom.xml 文件中的额外源或目标标签!

【讨论】:

    【解决方案2】:

    其实我也遇到过上面的报错信息,添加到属性文件后,错误得到解决。 :)

    property need to be added in pom.xml

     <properties>
            <maven.compiler.source>11</maven.compiler.source>
            <maven.compiler.target>11</maven.compiler.target>
        </properties>
    

    【讨论】:

      【解决方案3】:

      我通过匹配我的 IDE 和 pom.xml 文件之间的 jdk 纠正了这个问题。

      【讨论】:

        【解决方案4】:

        有时会从 Kotlin 更改为 java 或倒置。

        您也可以将 java 版本更改为更高版本。

        至少这对我有用。

        【讨论】:

          【解决方案5】:

          在 pom 文件中更改 maven 编译器版本解决了我的问题。 &lt;maven.compiler.source&gt;11&lt;/maven.compiler.source&gt; &lt;maven.compiler.target&gt;11&lt;/maven.compiler.target&gt;

          【讨论】:

          • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
          猜你喜欢
          • 2020-04-28
          • 1970-01-01
          • 1970-01-01
          • 2021-07-03
          • 2019-04-01
          • 2018-08-08
          • 2019-10-28
          • 1970-01-01
          相关资源
          最近更新 更多