2

I'm taking the UDEMY The Complete Apache Groovy Developer Course in section *112. Using REST based APIs' there is some sample code that is provided that doesn't work. The sample code is:

import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient

@Grab('org.codehaus.groovy.modules.http-builder:http-builder:0.7.1')

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
}

and the error is

groovy chuck.groovy
Caught: java.lang.NoClassDefFoundError: groovy/util/slurpersupport/GPathResult
java.lang.NoClassDefFoundError: groovy/util/slurpersupport/GPathResult

Problem: Trying to use HttpClient apparently fails because that code is using something in Groovy that doesn't exist (or that is my take on the issue).

The problem might be due to old HttpBuilder code trying to use something that is no longer in newer Groovy releases. (This is my suspicion).

The versions of Java and Groovy I'm using are:

groovy --version
Groovy Version: 4.0.0 JVM: 17.0.2 Vendor: Oracle Corporation OS: Windows 10

I tried searching for an answer to the problem and found https://stackoverflow.com/a/34814548/3281336 which offers a way to verify HttpBuilder is found but it also fails with the same error.

Searches on HttpBuilder show the software is quite old in software years (2014-ish was last update, see Maven Repository for HttpBuilder).

HttpBuilder has moved, see Where does the groovy http-builder module live now?.

Even a newer fork of HttpBuilder at https://github.com/http-builder-ng/http-builder-ng shows last commits in May 2020. I'll try that code next but need to learn a new way to import code to use it.

I'm heading back to the class and skipping this module for now, and will point to this link when asking about the problem. Perhaps the instructor will answer it. :-)

PatS
  • 8,833
  • 12
  • 57
  • 100

1 Answers1

0

HTTPBuilder does not work with groovy 4. Some of the components have moved packages in the move from codehaus to apache. It will work with groovy 3 with some minor modifications. It works fine with groovy 2.