I am having trouble working with an XML file in my Gradle script. The XML functionality works fine outside of my multi-project workspace, but within the workspace I get an error that looks like it’s caused by using an old version of Groovy. Here is my test code:
import groovy.xml.*
def xml = """
<a>
<b c="d" e="f"/>
<b c="g" e="h"/>
</a>
"""
def a = new XmlParser().parseText(xml)
println a.b.find{it.@e == "f"}.@c
a.b[0].@c = "z"
println XmlUtil.serialize(a)
a.b.find{it.@c == "g"}.@e = "y"
println XmlUtil.serialize(a)
To test, I’ve copied my gradlew and the “gradle” folder from my workspace to a temporary location. I’ve then copied this script, so the listing is:
mbrand@mac:~/tmp/gradleTest$ ls
quickTest.gradle gradle
gradlew
Running “./gradlew -b quickTest.gradle” runs successfully.
If I copy this to my multi-project workspace and run the same command, the build fails with:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/mbrand/ws/serverConfig/quickTest.gradle' line: 11
* What went wrong:
A problem occurred evaluating root project 'serverConfig'.
> No such field: e for class: groovy.util.Node
This looks like it’s accessing a very old version of Groovy. The question is, where is getting this version setting from? I can’t find anywhere in my code that I define the Groovy version. I’ve used the same Gradle wrapper in both locations.
Any idea what’s going on here or how I can resolve it?