Akka and scalatest in gradle

Posted on by  
Tammo Sminia

When you start using Scala, it's tempting to also start using sbt. You can also use your favorite build tool: Gradle. This is my default Gradle build file:

apply plugin: 'scala'

repositories {

dependencies {
  compile group: 'org.scala-lang', name: 'scala-library', version: '2.11.5'
  compile group: 'com.typesafe.akka', name: 'akka-actor_2.11', version: '2.3.9'
  compile group: 'com.typesafe.akka', name: 'akka-remote_2.11', version: '2.3.9'
  testCompile group: 'org.scalatest', name: 'scalatest_2.11', version: '2.2.4'

//run the akka application
task run(type: JavaExec, dependsOn: classes) {
  //object to run. (The one that extends App)
  main = 'pi.Pi'
  classpath sourceSets.main.runtimeClasspath
  classpath configurations.runtime

//run scala tests. These are not automatically picked up by gradle,
//so we run them like this.
task spec(dependsOn: ['testClasses'], type: JavaExec) {
  main = ''
  args = ['-R', 'build/classes/test', '-o']
  classpath = sourceSets.test.runtimeClasspath

Continue reading →