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
}

Interested in Scala? I send out weekly, personalized emails with articles and conference talks. Click here to see an example and subscribe.

1 reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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