问题描述
我有一个包含Guava的基于Maven的GWT项目。 Maven尝试(和失败)编译它在 guava-gwt * .jar 中找到的源代码时遇到了麻烦:
无法解析错误消息:symbol:static setCountImpl
location:class
/home/mark/.m2/repository/com/google/guava /guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com / google /common/collect/AbstractMultiset.java):100:错误:无法找到符号
返回setCountImpl(this,element,计数);
$
我无法弄清Maven为什么认为需要编译源代码番石榴GWT 。这是我的项目的样子:
├──pom.xml
└──src
├ ──main $ b $└──java
└──test
└──java
└──SomeTestFile.java
SomeTestFile.java
import com.google.common .collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import org.junit.Test;
public class SomeTestFile {
@Test
public void testMethod(){
Multimap< Integer,String> someMap = ArrayListMultimap.create();
someMap.put(5,five);
System.out.println(someMap);
}
}
pom.xml
<?xml version =1.0encoding =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>番石榴问题< / groupId>
< artifactId>番石榴问题< / artifactId>
< version> 1.0< / version>
<依赖关系>
< dependency>
< groupId> com.google.guava< / groupId>
< artifactId>番石榴< / artifactId>
< version> 11.0.1< / version>
< /依赖关系>
< dependency>
< groupId> com.google.guava< / groupId>
< artifactId> guava-gwt< / artifactId>
< version> 11.0.1< / version>
< /依赖关系>
< dependency>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 4.8.2< / version>
< /依赖关系>
< /依赖关系>
< build>
< plugins>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-compiler-plugin< / artifactId>
<配置>
< source> 1.6< / source>
< target> 1.6< / target>
< / configuration>
< / plugin>
< / plugins>
< / build>
< / project>
我已经尝试了以下内容:
- 删除 guava 依赖关系(只留下 guava-gwt )
- 范围 guava-gwt 至提供
我不知道还有什么可以尝试的。 guava-gwt 包含源代码,因为GWT会将其编译为等效的Javascript。但我不希望Maven尝试编译这些源代码。
编辑
只是一个注释。 。测试文件本身并不需要 guava-gwt over guava ,因为它们是作为Java代码编译和运行的(他们不通过GWT编译步骤)。我不需要 guava-gwt 专门用于这些测试,但它需要用于我的实际GWT客户端代码。
完整的Maven输出
mark @ mark-peters:〜/ devel / guava-problem $ mvn -V clean test-编译
Apache Maven 2.2.1(rdebian-1)
Java版本:1.7.0
Java home:/usr/lib/jvm/jdk1.7.0/jre
默认语言环境:en_US,平台编码:UTF-8
操作系统名称:linux版本:2.6.32-38-genericarch:amd64系列:unix
[INFO]扫描项目...
[信息] ---------------------------------------- --------------------------------
[信息]建设未命名 - 番石榴问题:番石榴问题: jar:1.0
[INFO] task-segment:[clean,test-compile]
[INFO] ---------------------- --------------------------------------------------
[INFO] [clean:clean {execution:default-clean}]
[INFO]删除文件集:/ home / mark / devel / guava-problem / target(included:[**],排除:[])
[信息] [资源:资源rces {execution:default-resources}]
[警告]使用平台编码(实际上是UTF-8)来复制已过滤的资源,即构建依赖于平台!
[INFO]跳过不存在的资源目录/ home / mark / devel / guava-problem / src / main / resources
[INFO] [编译器:编译{执行:默认编译}]
[INFO] Nothing to compile - 所有类都是最新的
[INFO] [resources:testResources {execution:default-testResources}]
[警告]使用平台编码(实际上是UTF-8)过滤资源,即构建是平台依赖的!
[INFO]跳过不存在的资源目录/ home / mark / devel / guava-problem / src / test / resources
[INFO] [compiler:testCompile {execution:default-testCompile}]
[INFO]将1个源文件编译为/ home / mark / devel / guava-problem / target / test-classes
[INFO] ------------------- -------------------------------------------------- ---
[错误] BUILD FAILURE
[INFO] ------------------------------- -----------------------------------------
[信息]编译失败
/home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar (com/google/common/collect/ AbstractMultiset.java):[19,0]错误:无法找到符号
无法解析错误消息:symbol:static setCountImpl
location:class
/ home / mark /。 m2 / repository / com / google / guava / guava-gwt / 11.0.1 / guava-gwt-11.0.1.jar(com / google / common / collect / AbstractMultiset.java):100:error:can not find symbol
返回setCountImpl(this,element,count);
$
无法解析错误信息:symbol:method setCountImpl(AbstractMultiset< E>,E,int)
location:class AbstractMultiset< E>
其中E是类型变量:
E extends类AbstractMultiset中声明的对象
/home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1 /guava-gwt-11.0.1.jar(com/google/common/collect/AbstractMultiset.java):105:错误:找不到符号
返回setCountImpl(this,element,oldCount,newCount);
^
[信息] ------------------------------ ------------------------------------------
[INFO] For更多信息,用-e开关运行Maven
[INFO] --------------------------------- ---------------------------------------
[信息]总时间:2秒
[INFO]完成时间:星期二Feb 21 12:49:42 EST 2012
[INFO] Final Memory:18M / 212M
[INFO] --------- -------------------------------------------------- -------------
编辑(再次)
发现问题的根源与Guava无关,而是Maven版本(请参阅),我已经更新了标题和问题,希望对未来的用户有更多的帮助。
因为Maven试图解析在JDK 7中已经改变的javac输出。F解释
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
$ bpom.xml
c><?xml version =1.0encoding =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>
<配置>
< compilerArgument> -Xlint:all< / compilerArgument>
< showWarnings> true< / showWarnings>
< showDeprecation> true< / showDeprecation>
< / configuration>
< / plugin>
< / plugins>
< / build>
< / project>
ClassWithWarnings.java
public class ClassWithWarnings implements java.io.Serializable {}
Maven坦克在这个项目以及使用Java 7时:
mark @ mark-peters:〜/ devel / maven-problem $ mvn -V编译
Apache Maven 2.2.1(rdebian-1)
Java版本:1.7.0
Java home:/usr/lib/jvm/jdk1.7.0/jre
默认语言环境:en_US,平台编码:UTF-8
操作系统名称:linux版本:2.6.32-38-genericarch:amd64系列:unix
[信息]扫描项目...
[信息] ------------------------------------- -----------------------------------
[INFO]构建未命名 - maven-problem:maven -problem:jar:1.0
[INFO] task-segment:[compile]
[INFO] ----------------------- -------------------------------------------------
[INFO] [resources:resources {execution:default-resources}]
[警告]使用平台编码(UTF-8 ac )复制过滤的资源,即构建依赖于平台!
[INFO]跳过不存在的资源目录/ home / mark / devel / maven-problem / src / main / resources
[INFO] [编译器:编译{执行:默认编译}]
[INFO]将1个源文件编译为/ home / mark / devel / maven-problem / target / classes
[INFO] --------------------- -------------------------------------------------- -
[错误] BUILD FAILURE
[INFO] --------------------------------- ---------------------------------------
[信息]编译失败
无法解析错误信息:警告:[选项] bootstrap类路径未与-source 1.3一起设置
/home/mark/devel/maven-problem/src/main/java/ClassWithWarnings.java:1 :警告:[serial]可序列化的类ClassWithWarnings没有serialVersionUID的定义
public class ClassWithWarnings implements java.io.Serializable {}
^
[INFO] - -------------------------------------------------- ---------------------
[INFO]有关更多信息,请使用-e开关运行Maven h
[信息] ------------------------------------------ ------------------------------
[信息]总时间:< 1秒
[INFO]完成于:星期二2月21日13:10:47东部标准时间2012
[INFO]最终记忆:14M / 150M
[信息] -------- -------------------------------------------------- ---------------
对于Java 6,它仍然会报告警告,但可以解析Javac输出,因此不会出现坦克:
Apache Maven 2.2.1(rdebian-1)
Java版本:1.6.0_20
Java主页:/ usr / lib / jvm / java-6-openjdk / jre
默认语言环境:en_US,平台编码:UTF-8
操作系统名称:linux版本:2.6.32-38-genericarch:amd64系列:unix
[信息]扫描项目...
[信息] --- -------------------------------------------------- -------------------
[INFO]构建未命名 - maven-problem:maven-problem:jar:1.0
[INFO] task-segment :[compile]
[INFO] --------------------------------------- ---------------------------------
[信息] [资源:资源{执行:默认资源}]
[警告]使用平台编码( UTF-8实际上)复制过滤资源,即构建依赖于平台!
[INFO]跳过不存在的资源目录/ home / mark / devel / maven-problem / src / main / resources
[INFO] [编译器:编译{执行:默认编译}]
[INFO]将1个源文件编译为/ home / mark / devel / maven-problem / target / classes
[警告] /home/mark/devel/maven-problem/src/main/java/ClassWithWarnings.java: [1,7] [serial]可序列化的类ClassWithWarnings没有serialVersionUID的定义
[INFO] ----------------------- -------------------------------------------------
[信息]建立成功
[信息] ----------------------------------- -------------------------------------
[信息]总时间:< 1秒
[INFO]完成时间:星期二2月21日13:18:39东部标准时间2012
[INFO]最终记忆:9M / 150M
[信息] -------- -------------------------------------------------- --------------
所以看起来好像问题最新的Maven 2版本不知道如何解析来自Java 7 + javac的错误消息。 Maven 3呢。我还没有找到这方面的文档,并且有点惊讶,当Maven试图针对JDK版本进行编译时,Maven并没有给出警告,因为它不知道如何正确支持。
I have a maven-based GWT project that includes Guava. I am running into trouble with Maven trying (and failing) to compile the sources that it finds in guava-gwt*.jar:
could not parse error message: symbol: static setCountImpl location: class /home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com/google/common/collect/AbstractMultiset.java):100: error: cannot find symbol return setCountImpl(this, element, count); ^
I can't figure out why Maven thinks it needs to compile the sources in guava-gwt. Here's what my project looks like:
├── pom.xml └── src ├── main │ └── java └── test └── java └── SomeTestFile.java
SomeTestFile.java
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import org.junit.Test; public class SomeTestFile { @Test public void testMethod() { Multimap<Integer, String> someMap = ArrayListMultimap.create(); someMap.put(5, "five"); System.out.println(someMap); } }
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>guava-problem</groupId> <artifactId>guava-problem</artifactId> <version>1.0</version> <dependencies> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>11.0.1</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava-gwt</artifactId> <version>11.0.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> </project>
I have already tried the following:
- Removing the guava dependency (leaving only guava-gwt)
- Scoping guava-gwt to provided
I'm not sure what else to try. guava-gwt includes sources because GWT will compile it into equivalent Javascript. But I don't want Maven to try to compile these sources.
Edit
Just a note...the test files themselves have no real need for guava-gwt over guava since they are compiled and run as Java code (they don't go through the GWT compile step). I don't need guava-gwt specifically for these tests but it needs to be available for my actual GWT client code.
Full Maven Output
mark@mark-peters:~/devel/guava-problem$ mvn -V clean test-compile Apache Maven 2.2.1 (rdebian-1) Java version: 1.7.0 Java home: /usr/lib/jvm/jdk1.7.0/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux" version: "2.6.32-38-generic" arch: "amd64" Family: "unix" [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building Unnamed - guava-problem:guava-problem:jar:1.0 [INFO] task-segment: [clean, test-compile] [INFO] ------------------------------------------------------------------------ [INFO] [clean:clean {execution: default-clean}] [INFO] Deleting file set: /home/mark/devel/guava-problem/target (included: [**], excluded: []) [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/guava-problem/src/main/resources [INFO] [compiler:compile {execution: default-compile}] [INFO] Nothing to compile - all classes are up to date [INFO] [resources:testResources {execution: default-testResources}] [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/guava-problem/src/test/resources [INFO] [compiler:testCompile {execution: default-testCompile}] [INFO] Compiling 1 source file to /home/mark/devel/guava-problem/target/test-classes [INFO] ------------------------------------------------------------------------ [ERROR] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Compilation failure /home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com/google/common/collect/AbstractMultiset.java):[19,0] error: cannot find symbol could not parse error message: symbol: static setCountImpl location: class /home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com/google/common/collect/AbstractMultiset.java):100: error: cannot find symbol return setCountImpl(this, element, count); ^ could not parse error message: symbol: method setCountImpl(AbstractMultiset<E>,E,int) location: class AbstractMultiset<E> where E is a type-variable: E extends Object declared in class AbstractMultiset /home/mark/.m2/repository/com/google/guava/guava-gwt/11.0.1/guava-gwt-11.0.1.jar(com/google/common/collect/AbstractMultiset.java):105: error: cannot find symbol return setCountImpl(this, element, oldCount, newCount); ^ [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2 seconds [INFO] Finished at: Tue Feb 21 12:49:42 EST 2012 [INFO] Final Memory: 18M/212M [INFO] ------------------------------------------------------------------------
Edit (again)
Having found that the source of the problem has nothing to do with Guava but rather the Maven version (see my answer), I've updated the title and question to try to be a lot more helpful to future users.
tl;dr
Maven 2 and JDK 7 are incompatible, as Maven tries to parse javac output which has changed in JDK 7.
Full explanation
Raghuram's note that this worked for him in Maven 3+ took me down the road of exploring this not as a config problem but as an actual Maven problem. I started doing more testing and found that this problem:
- Occurs with Java 7 and Maven 2.2.1
- Does not occur with Java 7 and Maven 3+
- Does not occur with Java 6 and Maven 2.2.1
So at that point it became clear to me that the "could not parse error message" errors were relevant, and the problem probably had less to do with the guava-gwt compilation occurring and more to do with Maven not knowing how to handle the errors properly.
To test this I created a separate Maven project that has nothing to do with Guava:
├── 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 {}
Lo and behold, Maven tanks on this project as well when using Java 7:
mark@mark-peters:~/devel/maven-problem$ mvn -V compile Apache Maven 2.2.1 (rdebian-1) Java version: 1.7.0 Java home: /usr/lib/jvm/jdk1.7.0/jre Default locale: en_US, platform encoding: UTF-8 OS 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 failure could 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 serialVersionUID public 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] ------------------------------------------------------------------------
With Java 6, it still reports the warnings, but can parse the Javac output and so doesn't tank:
Apache Maven 2.2.1 (rdebian-1) Java version: 1.6.0_20 Java home: /usr/lib/jvm/java-6-openjdk/jre Default locale: en_US, platform encoding: UTF-8 OS 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] ------------------------------------------------------------------------
So it seems as if the problem was that the latest Maven 2 release doesn't know how to parse error messages from Java 7+ javac. Maven 3 does. I still haven't found documentation of this and am a little surprised that Maven doesn't give a warning when it tries to compile against a JDK version that it doesn't know how to support properly.
这篇关于Maven“无法解析错误消息” (Java 7 + Maven 2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!