【问题标题】:Java maven build failure with source 1.7 (or 7)源代码 1.7(或 7)的 Java maven 构建失败
【发布时间】:2014-06-25 22:06:57
【问题描述】:

我正在将我的 java 6 代码升级到 java 7。已更新 JAVA_HOME 以指向 OS X 10.9 上的 JDK 1.7。该代码尚未使用任何 Java 7 功能。

当我运行构建“mvn clean install”时,构建中断,没有任何有用的错误消息。

构建成功,source=1.6 & target=1.6 但是对于 source=1.7(或 7)和 target=1.7(或 7)失败

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version> <!-- tried with 2.3.2 and 3.0... no luck -->
        <configuration>
          <source>7</source>
          <target>7</target>
          <compilerArgument>-Werror </compilerArgument>
          <fork>true</fork>
        </configuration>

Error Message:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.773 s
[INFO] Finished at: 2014-06-25T14:56:13-08:00
[INFO] Final Memory: 10M/245M
[INFO] ------------------------------------------------------------------------
[**ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (default-testCompile) on project core: Compilation failure
[ERROR] Failure executing javac,  but could not parse the error:
[ERROR] 1 error
[ERROR] -> [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/MojoFailureException

【问题讨论】:

  • mvn --version 输出什么?
  • 以及使用mvn -e的输出
  • 对于初学者来说,7 不是合法版本。将其更改为正确的1.7 并重试。

标签: java maven java-7


【解决方案1】:

我猜用 JDK 1.7 编译代码会产生警告,而用 1.6 编译则不会。由于您告诉编译器在遇到&lt;compilerArgument&gt;-Werror &lt;/compilerArgument&gt; 的警告时简单地退出,这正是它正在做的事情,这对 Maven 不是很友好。我猜 Maven 吞下了原始警告,转而显示 javac 进程意外退出的错误。

删除&lt;compilerArgument&gt;-Werror &lt;/compilerArgument&gt; 指令应该允许编译继续。您必须以一种比仅仅让编译器退出更好的方式来处理编译器警告,也许是通过查看/解析 Maven 输出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-09
    • 2021-10-19
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多