Scala FSC Issues - Potential Workaround


(Randall Minster) #1

I wasn’t able to get the FSC integration working with the Scala plugin. I’m convinced it’s an issue with the Scala ant tasks (I had similar issues outside of Gradle). Moreover, the Ant tasks appear to be looking for the scala executable on the path. This presents another issue because it requires installing the full Scala distribution. Gradle is so awesome, I shouldn’t need to :slight_smile:

As a workaround, I had some luck invoking the ‘CompileClient’ class directly, so I wanted to share the idea. Maybe something like the following implemented in a plugin would provide better results.

Overwriting the ‘compileScala’ class as follows seemed to invoke FSC properly. It also doesn’t require a Scala installation. And of course it improved build times.

task compileScala(type: JavaExec, overwrite: true) {
 doFirst {sourceSets.main.output.classesDir.mkdirs()}
 main 'scala.tools.nsc.CompileClient'
 classpath configurations.scalaTools
 args(
  ['-d', sourceSets.main.output.classesDir,
   '-classpath', sourceSets.main.runtimeClasspath.asPath] +
   sourceSets.main.allScala.collect{it.toString()}
 )
}

Hopefully, this gets the main idea across. I’m sure there is plenty of room for improvement.


(Peter Badenhorst) #2

In case it doesn’t work for you, make sure the class path is surrounded with quotes:

task compileScala(type: JavaExec, overwrite: true) {

doFirst {sourceSets.main.output.classesDir.mkdirs()}

main ‘scala.tools.nsc.CompileClient’

classpath configurations.scalaTools

args(

[’-d’, sourceSets.main.output.classesDir,

‘-classpath’, “”$sourceSets.main.runtimeClasspath.asPath""] +

sourceSets.main.allScala.collect{it.toString()}

)

}