Running ant.exec with env attribute

Hi I’m using ant.exec to start and spawn a process but I can’t get the ‘env’ attribute to work. From the Ant documentation “It is possible to specify environment variables to pass to the system command via nested <env> elements.”

ant.exec(executable: "/usr/bin/node", spawn: "true") {
    env(key: "NODE_PATH", value = "/usr/lib/node_modules")
    arg(value: "$projectDir/restStaticServer/js/restAndStaticServer.js")
    arg(value: "logging=true")
}

This results in the following error:

Execution failed for task ':startProxyServer'.
> No signature of method: java.util.Collections$UnmodifiableMap.call() is applicable for argument types: (java.util.LinkedHashMap, java.lang.String) values: [[key:NODE_PATH], /usr/lib/node_modules]
  Possible solutions: wait(), any(), clear(), size(), values(), grep()

I don’t get any errors if I remove the ‘env’ attribute. Is setting the env attribute supported? If so am I doing something wrong?

This is using Gradle 2.5 on Ubuntu 14.04.

Thanks,
Rich.

It should be like this (multiple env are allowed):

env(key: "NODE_PATH", value: "/usr/lib/node_modules")

Thanks for the quick response. I tried that but get exactly the same problem (I originally had the env attribute in that format but must have left the equals in there after a failed attempt at fixing the error).

ant.exec(executable: “/usr/bin/node”, spawn: “true”, failonerror: “true”) {
env(key: “NODE_PATH”, value: “/usr/lib/node_modules”)
arg(value: “$projectDir/restStaticServer/js/restAndStaticServer.js”)
arg(value: “logging=true”)
}

Same error:

Execution failed for task ‘:startProxyServer’.
No signature of method: java.util.Collections$UnmodifiableMap.call() is applicable for argument types: (java.util.LinkedHashMap) values: [[key:NODE_PATH, value:/usr/lib/node_modules]]
Possible solutions: wait(), any(), wait(long), take(int), any(groovy.lang.Closure), max(groovy.lang.Closure)