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

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.

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

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

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.

Setting an empty source path solves the problem:

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

this helps, thank you.

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!

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

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

Yes, that’s what happens.

perfect, thanks.