scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Duplicate Class Error when using vaadin (which contains java-files) #10108

Closed scabug closed 7 years ago

scabug commented 7 years ago

Hi,

when scala is cross compiling java files, I get an duplicate class error:

Executing org.gradle.api.internal.tasks.scala.ZincScalaCompiler@23c084bd in compiler daemon.
Compiling with Zinc Scala compiler.
Compiling 1 Java source to /Users/ggr/Downloads/demo/build/classes/main...
/Users/ggr/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-server/7.7.5/28bc909336b9b399d93926b99148ce66d1bf3ed3/vaadin-server-7.7.5.jar(com/vaadin/annotations/JavaScript.java):58: error: duplicate class: com.vaadin.annotations.JavaScript
public @interface JavaScript {
        ^
/Users/ggr/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-server/7.7.5/28bc909336b9b399d93926b99148ce66d1bf3ed3/vaadin-server-7.7.5.jar(com/vaadin/server/Page.java):36: error: cannot access JavaScript
import com.vaadin.ui.JavaScript;
                    ^
  bad source file: /Users/ggr/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-server/7.7.5/28bc909336b9b399d93926b99148ce66d1bf3ed3/vaadin-server-7.7.5.jar(com/vaadin/ui/JavaScript.java)
    file does not contain class com.vaadin.ui.JavaScript
    Please remove or make sure it appears in the correct subdirectory of the sourcepath.
Exception executing org.gradle.api.internal.tasks.scala.ZincScalaCompiler@23c084bd in compiler daemon: org.gradle.api.internal.tasks.compile.CompilationFailedException: javac returned nonzero exit code.
:compileScala FAILED
:compileScala (Thread[main,5,main]) completed. Took 4.81 secs.

When I remove the java files in the vaadin-server jar file, it works. When I only use java (no scala) it is also no problem, that java files are contained in the jar side to side with the class files.

Demo to reproduce problem is attached. Just extract, go in and type ./gradlew clean testClasses --info

scabug commented 7 years ago

Imported From: https://issues.scala-lang.org/browse/SI-10108?orig=1 Reporter: Guenther Grill (guenther) Affected Versions: 2.11.8 Attachments:

scabug commented 7 years ago

@lrytz said: "Please remove or make sure it appears in the correct subdirectory of the sourcepath" sounds like gradle / zinc is passing /Users/ggr/.gradle/caches/modules-2/files-2.1/com.vaadin/vaadin-server/7.7.5/28bc909336b9b399d93926b99148ce66d1bf3ed3/vaadin-server-7.7.5.jar as -sourcepath.

Also, the error ("bad source file") seems to come from the Java compiler, not the Scala compiler. So it seems not to be a bug on our end.