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 = [
 "org.scala-lang:scala-actors:$scalaVersion@jar",
 "org.scala-lang:scala-compiler:$scalaVersion@jar",
 "org.scala-lang:scala-library:$scalaVersion@jar",
 "org.scala-lang:scala-reflect:$scalaVersion@jar"
]
  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 {
 scalaLibs
}
  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 org.apache.tools.ant.ComponentHelper.checkTaskClass(ComponentHelper.java:376)
        at org.apache.tools.ant.ComponentHelper.addTaskDefinition(ComponentHelper.java:341)
        at org.apache.tools.ant.Project.addTaskDefinition(Project.java:971)
        at org.apache.tools.ant.Project$addTaskDefinition.call(Unknown Source)
        at org.apache.tools.ant.Project$addTaskDefinition.call(Unknown 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(ClosureBackedAction.java:58)
        at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:133)
        at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:94)
        at org.gradle.util.ConfigureUtil$configure.call(Unknown Source)
        at org.gradle.api.internal.project.DefaultIsolatedAntBuilder.execute(DefaultIsolatedAntBuilder.groovy:112)
        at org.gradle.api.internal.project.IsolatedAntBuilder$execute.call(Unknown 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(DefaultScalaJavaJointCompiler.java:35)
        at org.gradle.api.internal.tasks.scala.DefaultScalaJavaJointCompiler.execute(DefaultScalaJavaJointCompiler.java:25)
        at org.gradle.api.internal.tasks.scala.DelegatingScalaCompiler.execute(DelegatingScalaCompiler.java:31)
        at org.gradle.api.internal.tasks.scala.DelegatingScalaCompiler.execute(DelegatingScalaCompiler.java:22)
        at org.gradle.api.internal.tasks.compile.IncrementalJavaCompilerSupport.execute(IncrementalJavaCompilerSupport.java:33)
        at org.gradle.api.internal.tasks.compile.IncrementalJavaCompilerSupport.execute(IncrementalJavaCompilerSupport.java:24)
        at org.gradle.api.tasks.scala.ScalaCompile.compile(ScalaCompile.java:133)
        at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:216)
        at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:122)
        at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
        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(AnnotationProcessingTaskFactory.java:217)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:199)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:526)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:509)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
        ... 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).)