Improving Performance of Gradle + Scala Build with a compiler daemon

If you find the build times of Scala programs in gradle unacceptably slow, you can add the following to build.gradle. This took my simple build from 25 seconds to five.

compileScala {
    scalaCompileOptions.useCompileDaemon = true

    // optionally specify host and port of the daemon:
    scalaCompileOptions.daemonServer = "localhost:4243"
}

This doesn’t seem to be stable all the time; an alternative approach is to set the following settings in build.gradle, which is almost as fast:

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

One Reply to “Improving Performance of Gradle + Scala Build with a compiler daemon”

Leave a Reply

Your email address will not be published. Required fields are marked *