Exception when using zinc for scala project


(Martin) #1

Hi,

I just tried to use zinc instead of ant but got the following exception (gradle 1.4, scala 2.10):

Executing org.gradle.api.internal.tasks.scala.jdk6.ZincScalaCompiler@329b0985 in compiler daemon.
Compiling with Zinc Scala compiler.
Exception executing org.gradle.api.internal.tasks.scala.jdk6.ZincScalaCompiler@329b0985 in compiler daemon: java.lang.NoSuchMethodError: scala.collection.JavaConverters$.asScalaBuf
ferConverter(Ljava/util/List;)Lscala/collection/JavaConverters$AsScala;.
:compileScala FAILED
  FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':compileScala'.
> scala.collection.JavaConverters$.asScalaBufferConverter(Ljava/util/List;)Lscala/collection/JavaConverters$AsScala;
  * Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
  BUILD FAILED

I added the following snippet to my gradle file. Do I have to do something else? Is it a configuration problem?

tasks.withType(ScalaCompile) {
    scalaCompileOptions.useAnt = false
    configure(scalaCompileOptions.forkOptions) {
        memoryMaximumSize = '1g'
        jvmArgs = ['-XX:MaxPermSize=512m']
    }
}

(Peter Niederwieser) #2

Can you show how you declared the Scala dependencies?

What’s the output of running the following?

task debug << {
  compileScala.scalaClasspath.each { println it }
}

Can you post the full stack trace (’-S’), preferably as a Gist?


(Martin) #3
project.ext {
 scalaVersion = '2.10.0'
  ...
    dependencies {
    scalaTools "org.scala-lang:scala-compiler:${scalaVersion}"
 compile "org.scala-lang:scala-library:${scalaVersion}"
...

Dependencies by using your task:

C:\Users…gradle\caches\artifacts-23\filestore\org.scala-lang\scala-compiler.10.0\jar\fec8066cd2b4f8dc7ff7ba7a8e0a792939d9f9a\scala-compiler-2.10.0.ja C:\Users…gradle\caches\artifacts-23\filestore\org.scala-lang\scala-library.10.0\jar3c6d98b445187c6b459a582c774ffb025120ef4\scala-library-2.10.0.jar C:\Users…gradle\caches\artifacts-23\filestore\org.scala-lang\scala-reflect.10.0\jar0ec1256a6e875e886fec050edb0669166912d0d\scala-reflect-2.10.0.jar

Stacktrace:

https://gist.github.com/4664148


(Peter Niederwieser) #4

You’ll have to set ‘scalaCompileOptions.fork=true’ to enable forking. Does this make a difference? Do you declare a Scala version other than 2.10.0 anywhere in the build? Do you override the defaults for ‘dependencies { zinc … }’? Can you provide a self-contained reproducible example?


(Martin) #5

ok, got it working. Problem was the following:

I had turned on failOnVersionConflict with:

failOnVersionConflict()
  force(
                    ...
                    "org.scala-lang:scala-library:${scalaVersion}",
                    ...

In my dependencies there have been

compile 'com.yammer.metrics:metrics-scala_2.9.1:2.0.0-RC0'
      compile "com.wordnik:swagger-jaxrs_2.9.1:1.2.0"
    compile "com.wordnik:swagger-core_2.9.1:1.2.0"

which seems to have caused that exception. I forgot to update these dependencies when I moved to 2.10.

Following solution works now:

compile('com.yammer.metrics:metrics-scala_2.9.1:2.0.0-RC0'){
        exclude group: 'org.scala-lang', module: 'scala-library'
    }
      compile "com.wordnik:swagger-jaxrs_${scalaVersion}:1.2.0"
    compile "com.wordnik:swagger-core_${scalaVersion}:1.2.0"

Thanks for your help.


(Peter Niederwieser) #6

I think the problem was that this also forced the Scala version for the ‘zinc’ configuration, and as such Zinc itself (which is written in Scala) ended up with the wrong Scala library version. Anyway, glad you found a solution.