Task hanging upon trying to execute a Scala script


(Noel Yap) #1

I have the following task definition:

task small(dependsOn: configurations.compile) << {

def command = ["${projectDir}/setter-for-catan.scala"]

def env = null // []

println ([‘echo’, ‘********************** 0’].execute(env, null).text)

println (command.execute(env, null).text)

}

The contents of the Scala script is:

#!/bin/bash

echo ‘********************* 1’ “$0” “$@”

/opt/scala-2.10.1/bin/scala “$0” “$@” 2>&1

!#

object ‘setter-for-catan’ {

def main(args: Array[String]) {

println("****************** 2")

}

}

This gives the following output:

$ g small

:small

********************** 0

********************* 1 /Users/nyap/proj/setter-for-catan/setter-for-catan.scala

****************** 2

BUILD SUCCESSFUL

If ‘env’ is defined as ‘[]’, Gradle hangs with the following output:

$ g small

:small

********************** 0

Building > :small

If ‘"$0" “$@”’ is then changed to ‘-version’, the build stops hanging with the following output:

$ g small

:small

********************** 0

********************* 1 /Users/nyap/proj/setter-for-catan/setter-for-catan.scala

Scala code runner version 2.10.1 – Copyright 2002-2013, LAMP/EPFL

BUILD SUCCESSFUL

What’s going on? Should I ask a Groovy community instead?


(Noel Yap) #2

The following Groovy script exhibits the same hanging problem:

#!/opt/groovy-1.8.6/bin/groovy

final command = ["./setter-for-catan.scala"]

final env = []

println ([‘echo’, ‘********************** 0’].execute(env, null).text)

println (command.execute(env, null).text)

so it does look to be a Groovy/Scala issue.


(Luke Daley) #3

I suspect the Scala process is not exiting. If you run just the bash script by itself what happens?


(Noel Yap) #4

The Scala script runs fine by itself. It turned out that the Scala script wasn’t inheriting the JAVA_HOME setting.

http://stackoverflow.com/questions/17396036/why-does-groovy-execute-hang/17397050#17397050