My project includes both java and scala files. My sourcesets are configure as
sourceSets {
main {
scala {
srcDirs = [ 'src/scala', 'src/java' ]
}
}
}
After a successful compile, I change one of my scala files. I would expect only the scala file that change would get compiled, but ALL of the scala files are recompiled.
0:44:29.469 [DEBUG] [org.gradle.api.internal.tasks.scala.AntScalaCompiler] Ant scalac task options: {destDir=C:\myproject\build\classes\main, target=jvm-1.7, fork=false, unchecked=on, addparams=-feature, deprecation=on, scalacdebugging=false, force=never, failOnError=true}
10:44:30.403 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] fileset: Setup scanner in dir C:\myproject\src\scala with patternSet{ includes: [] excludes: [] }
10:44:30.729 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:scalac] com\someFile.scala added as com\someFile.class doesn't exist.
This is repeated for every scala file. Even though they haven’t changed. What’s odd is that it says the class file doesn’t exist, which clearly it does. It appears that it’s not even looking for the class files in the appropriate directory.
I was able to replicate the issue with the gradle 1.11 mixedJavaAndScala sample: After a successful build I modified the PersonImpl.class. Here is the output after I run the build again:
13:17:33.336 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] fileset: Setup scanner in dir C:\gradle-1.11\samples\scala\mixedJavaAndScala\src\main\scala with patternSet{ includes: [] excludes: [] }
13:17:33.361 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:scalac] org\gradle\sample\impl\PersonImpl.scala added as org\gradle\sample\impl\PersonImpl.class doesn't exist.
13:17:33.371 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:scalac] org\gradle\sample\impl\PersonList.scala added as org\gradle\sample\impl\PersonList.class doesn't exist.
13:17:33.410 [INFO] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:scalac] Compiling 2 scala and 1 java source files to C:\gradle-1.11\samples\scala\mixedJavaAndScala\build\classes\main
13:17:33.422 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:scalac] org\gradle\sample\impl\PersonImpl.scala
13:17:33.431 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:scalac] org\gradle\sample\impl\PersonList.scala
13:17:33.443 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:scalac] org\gradle\sample\impl\JavaPerson.java
Can anyone from Gradle confirm this and create a ticket?
The Ant Scala compiler doesn’t support incremental compilation. To get incremental compilation, you need to use the Zinc Scala compiler. See “25.10. Incremental compilation” in the Gradle User Guide.
I suppose ‘force=never’ doesn’t work as expected because Gradle’s Ant Scala compiler always cleans previously generated class files before recompiling to avoid stale class files. In any case, if you are after partial recompilation, it’s much better to use the Zinc compiler.
Peter,
Thank you for the feed back. I’ll give the Zinc compiler a try. Is it possible to override the scalaTools configuration to use scala 2.10.3?
Thanks!
Yes, but the ‘scalaTools’ configuration was deprecated a while ago. Now all you need to do is to add the desired scala-library version as a compile dependency.