tl; dr
Maven 2和JDK 7不兼容,因为Maven尝试解析JDK 7中已更改的javac输出。
完整说明
Raghuram的说明说,这在Maven
3+中对他有用,这使我沿着探索这个问题的道路不再是配置问题,而是一个实际的Maven问题。我开始做更多测试,发现这个问题:
- 随Java 7和Maven 2.2.1一起出现
- Java 7和Maven 3+不会发生
- Java 6和Maven 2.2.1不会发生
因此,从那时起,我很清楚“无法解析错误消息”错误是相关的,问题可能与 发生 的
guava-gwt编译无关,而与Maven不知道如何正确处理错误有关。
__
为了测试这一点,我创建了一个与Guava无关的单独的Maven项目:
├── pom.xml└── src └── main └── java └── ClassWithWarnings.java
pom.xml
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>maven-problem</groupId> <artifactId>maven-problem</artifactId> <version>1.0</version> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <compilerArgument>-Xlint:all</compilerArgument> <showWarnings>true</showWarnings> <showDeprecation>true</showDeprecation> </configuration> </plugin> </plugins> </build></project>
ClassWithWarnings.java
public class ClassWithWarnings implements java.io.Serializable {}瞧,使用Java 7时,Maven也会在该项目上出现问题:
mark@mark-peters:~/devel/maven-problem$ mvn -V compileApache Maven 2.2.1 (rdebian-1)Java version: 1.7.0Java home: /usr/lib/jvm/jdk1.7.0/jreDefault locale: en_US, platform encoding: UTF-8OS name: "linux" version: "2.6.32-38-generic" arch: "amd64" Family: "unix"[INFO] Scanning for projects...[INFO] ------------------------------------------------------------------------[INFO] Building Unnamed - maven-problem:maven-problem:jar:1.0[INFO] task-segment: [compile][INFO] ------------------------------------------------------------------------[INFO] [resources:resources {execution: default-resources}][WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent![INFO] skip non existing resourceDirectory /home/mark/devel/maven-problem/src/main/resources[INFO] [compiler:compile {execution: default-compile}][INFO] Compiling 1 source file to /home/mark/devel/maven-problem/target/classes[INFO] ------------------------------------------------------------------------[ERROR] BUILD FAILURE[INFO] ------------------------------------------------------------------------[INFO] Compilation failurecould not parse error message: warning: [options] bootstrap class path not set in conjunction with -source 1.3/home/mark/devel/maven-problem/src/main/java/ClassWithWarnings.java:1: warning: [serial] serializable class ClassWithWarnings has no definition of serialVersionUIDpublic class ClassWithWarnings implements java.io.Serializable {} ^[INFO] ------------------------------------------------------------------------[INFO] For more information, run Maven with the -e switch[INFO] ------------------------------------------------------------------------[INFO] Total time: < 1 second[INFO] Finished at: Tue Feb 21 13:10:47 EST 2012[INFO] Final Memory: 14M/150M[INFO] ------------------------------------------------------------------------使用Java 6时,它仍会报告警告,但可以解析Javac输出,因此不会运行:
Apache Maven 2.2.1 (rdebian-1)Java version: 1.6.0_20Java home: /usr/lib/jvm/java-6-openjdk/jreDefault locale: en_US, platform encoding: UTF-8OS name: "linux" version: "2.6.32-38-generic" arch: "amd64" Family: "unix"[INFO] Scanning for projects...[INFO] ------------------------------------------------------------------------[INFO] Building Unnamed - maven-problem:maven-problem:jar:1.0[INFO] task-segment: [compile][INFO] ------------------------------------------------------------------------[INFO] [resources:resources {execution: default-resources}][WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent![INFO] skip non existing resourceDirectory /home/mark/devel/maven-problem/src/main/resources[INFO] [compiler:compile {execution: default-compile}][INFO] Compiling 1 source file to /home/mark/devel/maven-problem/target/classes[WARNING] /home/mark/devel/maven-problem/src/main/java/ClassWithWarnings.java:[1,7] [serial] serializable class ClassWithWarnings has no definition of serialVersionUID[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESSFUL[INFO] ------------------------------------------------------------------------[INFO] Total time: < 1 second[INFO] Finished at: Tue Feb 21 13:18:39 EST 2012[INFO] Final Memory: 9M/150M[INFO] ------------------------------------------------------------------------因此,似乎问题在于最新的Maven 2版本不知道如何解析来自Java 7+ javac的错误消息。Maven
3做到了。我仍然没有找到有关此问题的文档,当Maven尝试针对不知道如何正确支持的JDK版本进行编译时,它没有给出警告,这让我感到有些惊讶。



