我想将我们的一个项目从ant + ivy迁移到gradle。当我使用gradle编译源代码时出现此错误:
...\guava-gwt-14.0.1.jar(com/google/common/collect/AbstractIterator.java):64: error: duplicate class: com.google.common.collect.AbstractIterator
public abstract class AbstractIterator<T> extends UnmodifiableIterator<T> {
^
...\guava-gwt-14.0.1.jar(com/google/common/base/Optional.java):223: error: cannot access AbstractIterator
return new AbstractIterator<T>() {
^
bad source file: ...\guava-gwt-14.0.1.jar(com/google/common/base/AbstractIterator.java)
file does not contain class com.google.common.base.AbstractIterator
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors
我检查AbstractIterator.java
位于com.google.common.collect
和com.google.common.base
(错误地写了)。如何解决这个问题?
[UPDATE]
这是我的gradle构建(非常简单 - 它是从ant到gradle的迁移的开始)
apply plugin: 'java'
compileJava.options.encoding = 'ISO-8859-1'
repositories {
mavenCentral()
maven {
url 'http://gwtquery-plugins.googlecode.com/svn/mavenrepo'
}
ivy {
url 'http://ivyrep/shared'
url 'http://ivyrep/public'
layout "pattern", { artifact "[organisation]/[module]/[revision]/[type]s/[artifact].[ext]" }
}
}
// I know that conigurations should be repaired (testCompile, runtime) but this is just the beggining of migration from ant to gradle
dependencies {
compile 'net.sourceforge.cobertura:cobertura:1.9.4.1'
compile 'com.google.gwt:gwt-servlet:2.5.0'
compile 'com.google.gwt:gwt-user:2.5.0'
compile 'com.google.gwt:gwt-dev:2.5.0'
compile 'com.google.gwt.inject:gin:2.0.0'
compile 'com.googlecode.gwtquery:gwtquery:1.3.2'
compile 'com.googlecode.gwtquery.bundles:gquery-dnd-bundle:1.0.6'
compile 'org.hamcrest:hamcrest-library:1.3'
compile 'org.mockito:mockito-all:1.9.5'
compile 'junit:junit:4.10'
compile 'org.easytesting:fest-assert-core:2.0M10'
compile 'xmlunit:xmlunit:1.3'
compile 'org.reflections:reflections:0.9.9-RC1'
}
我还应该补充一点,这是一个 GWT项目。
[UPDATE]
问题解决了。我已经从编译范围中排除了guava-gwt,它开始起作用了。这可能不是最好的解决方案,但它确实有效。
apply plugin: 'java'
configurations { guavaGwt }
dependencies {
guavaGwt 'com.google.guava:guava-gwt:14.0.1'
// other dependencies
}
task compileGwt (dependsOn: classes) << {
// [...]
javaexec {
main = 'com.google.gwt.dev.Compiler'
maxHeapSize = '512M'
classpath {
[
sourceSets.main.java.srcDirs,
sourceSets.main.output.resourcesDir,
sourceSets.main.output.classesDir,
sourceSets.main.compileClasspath,
configurations.guavaGwt, // USE guava-gwt
]
}
args =
[
moduleName,
'-war',
buildDir,
'-logLevel',
'INFO',
// '-draftCompile' // Speeds up compile with 25%
]
}
// [...]
}
compileJava {
configurations.compile.exclude module:'guava-gwt' // exclude guava-gwt
// do the job
}
答案 0 :(得分:2)
我今天遇到了同样的问题,并通过将其添加到我的gradle构建文件来修复它:
tasks.withType(JavaCompile) {
options.compilerArgs += ["-sourcepath", ""]
}
感谢Peter在这篇文章中的回答:http://forums.gradle.org/gradle/topics/compilation_fails_when_i_use_guavas_optional_class_duplicate_class_com_google_common_collect_abstractiterator
答案 1 :(得分:0)
某些GWT Jars包含类和源。默认情况下,javac将尝试在类路径上编译源代码,这可能是您收到此错误的原因。这应该解决它:
tasks.withType(JavaCompile) {
options.compilerArgs << '-implicit:none'
}
PS:你的常春藤回购声明正在覆盖自己的网址。相反,你要宣布两个常春藤回购。
答案 2 :(得分:0)
在使用ubuntu上的maven构建GWT项目时,我也遇到了这个错误。一位同事做了一些研究,发现以下编译器arg解决了这个问题:
-Xprefer:newer