I am new to Groovy and following a tutorial. Any help would be much appreciated. I also was unsuccessful in using @Grab.
It is a Groovy project without Maven or Gradle.
I have researched and couldn't find a solution, and the tutorial is not updated.
Course: The Complete Apache Groovy Developer Course
import groovyx.net.http.RESTClient
String base = 'http://api.icndb.com'
def chuck = new RESTClient(base)
def params = [firstName: "Dan", lastName: "Vega"]
chuck.contentType = ContentType.JSON
chuck.get( path: '/jokes/random', query: params ) { response, json ->
println response.status
println json
}
Error
Caught: java.lang.NoClassDefFoundError: groovy/util/slurpersupport/GPathResult
java.lang.NoClassDefFoundError: groovy/util/slurpersupport/GPathResult
at java.desktop/com.sun.beans.introspect.MethodInfo.get(MethodInfo.java:70)
at java.desktop/com.sun.beans.introspect.ClassInfo.getMethods(ClassInfo.java:80)
at groovyx.net.http.ParserRegistry.<init>(ParserRegistry.java:87)
at groovyx.net.http.HTTPBuilder.<init>(HTTPBuilder.java:194)
at groovyx.net.http.RESTClient.<init>(RESTClient.java:80)
at com.thesamoanppprogrammer.practicegroovy.restapi.httpbuilder.todos.run(todos.groovy:7)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Caused by: java.lang.ClassNotFoundException: groovy.util.slurpersupport.GPathResult
starting from groovy 3.0 GPathResult moved to another package: groovy.xml.slurpersupport.GPathResult
.
but according to error HTTPBuilder
is looking for old package groovy.util.slurpersupport.GPathResult
.
You have to downgrade groovy version, or upgrade HTTPBuilder