How to replace scalaTools configuration?

(Daniel Svojanovský) #1

I’m trying to get rid of deprecated scalaTools configuration, but so far I’m unable to find working solution.

This is working configuraiton:

apply plugin: 'idea'
apply plugin: 'scala'
  repositories {
 flatDir(name: 'libs', dirs: 'lib')
  def scalaVersion = '2.10.2'
  def scalaDeps = [
  dependencies {
 compile scalaDeps
 scalaTools scalaDeps

I’m able to build with no problem, gradle idea generates project correctly which means:

  • module has scala facet configured

  • there is a library with all four jar files configured (Project Structure > Libraries)

But when I try to change it as documentation suggests (adding library to compile configuration instead of scalaToos):

dependencies {
 compile scalaDeps

It ends up with

Execution failed for task ':compileScala'.
> scala/Option

Idea project structure scala library contains only ‘scala-compiler-2.10.2’ and attempt to rebuild project in idea ends with

‘scala: No ‘scala-library*.jar’ in Scala compiler library in gradle-scala’

My another attempt to fix this was to create special configuration and use it instead of scalaTools. It works with gradle, but idea project has still the problem decribed above (incompete library).

configurations {
  dependencies {
 compile scalaDeps
 scalaLibs scalaDeps
  tasks.withType(ScalaCompile) {
 scalaClasspath = files(configurations.scalaLibs)

So my only option is to stick with deprecated scalaTools configuration.

Any help would be appreciated.

Thank you.

(Peter Niederwieser) #2

Please provided the full stack trace. Why do you put ‘scala-compiler’ and ‘scala-reflect’ on the compile class path? Why do you use ‘@jar’?

(Daniel Svojanovský) #3

I had to add all those dependencies otherwise compilation always failed on missing classes.

We are using flatDir for depencencies and there are no poms. I thought it was necessary.

Caused by: java.lang.NoClassDefFoundError: scala/Option
        at$ Source)
        at$ Source)
        at org.gradle.api.internal.project.AntBuilderDelegate$_taskdef_closure1_closure2.doCall(DefaultIsolatedAntBuilder.groovy:139)
        at org.gradle.api.internal.project.AntBuilderDelegate$_taskdef_closure1.doCall(DefaultIsolatedAntBuilder.groovy:138)
        at org.gradle.api.internal.project.AntBuilderDelegate.taskdef(DefaultIsolatedAntBuilder.groovy:136)
        at org.gradle.api.internal.tasks.scala.AntScalaCompiler$_execute_closure1.doCall(AntScalaCompiler.groovy:62)
        at org.gradle.api.internal.ClosureBackedAction.execute(
        at org.gradle.util.ConfigureUtil.configure(
        at org.gradle.util.ConfigureUtil.configure(
        at org.gradle.util.ConfigureUtil$ Source)
        at org.gradle.api.internal.project.DefaultIsolatedAntBuilder.execute(DefaultIsolatedAntBuilder.groovy:112)
        at org.gradle.api.internal.project.IsolatedAntBuilder$ Source)
        at org.gradle.api.internal.tasks.scala.AntScalaCompiler.execute(AntScalaCompiler.groovy:61)
        at org.gradle.api.internal.tasks.scala.AntScalaCompiler.execute(AntScalaCompiler.groovy)
        at org.gradle.api.internal.tasks.scala.DefaultScalaJavaJointCompiler.execute(
        at org.gradle.api.internal.tasks.scala.DefaultScalaJavaJointCompiler.execute(
        at org.gradle.api.internal.tasks.scala.DelegatingScalaCompiler.execute(
        at org.gradle.api.internal.tasks.scala.DelegatingScalaCompiler.execute(
        at org.gradle.api.internal.tasks.compile.IncrementalJavaCompilerSupport.execute(
        at org.gradle.api.internal.tasks.compile.IncrementalJavaCompilerSupport.execute(
        at org.gradle.api.tasks.scala.ScalaCompile.compile(
        at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(
        at org.gradle.api.internal.BeanDynamicObject.invokeMethod(
        at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(
        at org.gradle.api.tasks.scala.ScalaCompile_Decorated.invokeMethod(Unknown Source)
        at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(
        ... 88 more
Caused by: java.lang.ClassNotFoundException: scala.Option
        ... 124 more

(Peter Niederwieser) #4

Oh I see, you are using a ‘flatDir’ repository. I’m afraid that automatic configuration of ‘ScalaCompile.scalaClasspath’ won’t work in this case. This is because the Scala plugin cannot reliably tell the transitive dependencies of a particular ‘scala-compiler’ version and hence relies on transitive dependency solution to bring them in (which won’t happen with a ‘flatDir’ repository). Hence you’ll have to set ‘scalaClasspath’ yourself. Something like:

tasks.withType(ScalaCompile) {
    scalaClasspath = files("lib/scala-compiler.jar", "lib/scala-reflect.jar", "lib/scala-library.jar")

(Peter Niederwieser) #5

You shouldn’t have to add ‘scala-compiler’ to the compile class path, unless you are using the compiler at runtime. ‘@jar’ shouldn’t be necessary, but with a ‘flatDir’ repo it won’t make a difference.

(Daniel Svojanovský) #6

Yes, this is what I did in the last scenario, but idea project is still misconfigured. So if I get that right, there are two options:

  1. don’t use flatDir for this particular module with scala 2. modify idea project myself

Any other option?

Thank you.

(Peter Niederwieser) #7

It’s the same problem (transitive dependencies are missing). I’m not aware of another option, sorry. What you can try is to just generate the missing bits of information (Jars for ‘scala-compiler’ liblary in .ipr).

(Daniel Svojanovský) #8

Ok, thank you for your help. I appreciate it.

(Peter Niederwieser) #9

I’ve raised GRADLE-2855 to track that scalaClasspath inference doesn’t work well with flatDir repositories. Some things we could do:

  • Not try to infer scalaClasspath if (only) flatDir repo is present * Not rely on transitive dependency resolution but encode knowledge of transitive dependencies for a particular scala-compiler version in Scala plugin. (Up until Scala 2.10, transitive dependencies only changed once (0 -> 2).)