12

I upgraded to groovy 2 release and now my build is broken.

It fails when importing classes: groovy.json.JsonSlurper and XmlSlurper.

I have checked http://groovy.codehaus.org/gapi/ and cannot find these classes anymore. Do they still exist in groovy 2? Or have they moved somewhere?

Steven
  • 3,844
  • 3
  • 32
  • 53

5 Answers5

11

The groovy.jar distributed with groovy 2 has been split out to contain just the bare minimum, with all the additional modules (XML, SQL, JSON, etc.) in separate jars. However, in the embeddable directory, you'll find a jar file groovy-all-2.0.0.jar which contains groovy and all the modules together, like previous versions. The easiest way to migrate is to use this jar file.

If you're using Maven Central, you can use an artifactId of groovy-all to get everything, or groovy (plus modules) to have finer grained control over your dependencies. Here's a list of the modules available on Maven Central: http://search.maven.org/#search|ga|1|g%3A%22org.codehaus.groovy%22

ataylor
  • 64,891
  • 24
  • 161
  • 189
6

Never mind. Need to include groovy-xml and groovy-json jars. These were split from groovy's jar. See: http://www.infoq.com/articles/new-groovy-20

Steven
  • 3,844
  • 3
  • 32
  • 53
1

When I import, groovy-json-2.4.3 and groovy-xml-2.4.3 , JsonSlurper is recognized.

Also refer for new code refactor after 1.8.0 version: Parsing array of JSON arrays in Groovy

Community
  • 1
  • 1
Raja
  • 695
  • 7
  • 8
1

I faced a similar issue in Gradle build of a Java project (Gradle uses Groovy).

Gradle stopped including the local Groovy libs in classpath automatically. So, I had to include the following lines (marked with +) in my build.gradle file:

buildscript {
    ext {
        springbootVersion = '2.x.x'
        awsVersion = '1.x.x'

        ...
    }
+    dependencies {
+        classpath localGroovy()
+    }
    repositories ...
}
Teddy
  • 4,009
  • 2
  • 33
  • 55
0

Instead of using "groovy.json.jsonSlurper", use "net.sf.json.groovy.JsonSlurper". Your script must be running.