compilation fails when I use Guava's Optional class: duplicate class:

(Alex Sko) #1

I see the problem is described here pretty well. we can’t use Optional class from Google Guava because it triggers the compilation error:

0.jar(com/google/common/collect/ error: duplicate class:
public abstract class AbstractIterator<T> extends UnmodifiableIterator<T> {
0.jar(com/google/common/base/ error: cannot access AbstractIterator
        return new AbstractIterator<T>() {
  bad source file: .gradle\caches\artifacts-24\filestore\\guava-gwt2.0\jar7db9cba72410110a02558741de7766939b
    file does not contain class
    Please remove or make sure it appears in the correct subdirectory of the sourcepath.

we already have

compileJava.options.compilerArgs = ["-implicit:none"]

in the build.gradle file.

compilation in the IDE (Jetbrains IDEA) works fine.

(David Ackerman) #2

Just to add to this - we are using Guava with GWT (just like in the StackOverflow article).

(Peter Niederwieser) #3

Can you provide a minimal self-contained sample build that allows to reproduce the problem?

(andrew.j.matheny) #4

Here is an example project which exhibits the same problem

I’ve also included an ant buildfile which has no problem compiling the same code.

(Peter Niederwieser) #5

Setting an empty source path solves the problem:

tasks.withType(JavaCompile) {
    options.compilerArgs += ["-sourcepath", ""]

(Alex Sko) #6

this helps, thank you.

(Evan Ruff) #7

Hate to dredge up an answered question, but could someone give me a quick explanation of why omitting the source path helps in this instance? Thanks!

(Peter Niederwieser) #8

By default, the class path is also used as source path. This can be prevented by setting a source path explicitly.

(Evan Ruff) #9

Wow thanks for such a quick reply. So the issue in the case of the GWT situation is that, because the JAR includes the source, it creates an ugly conflict? Thanks, E

(Peter Niederwieser) #10

Yes, that’s what happens.

(Evan Ruff) #11

perfect, thanks.