I'm trying to figure out how to use Spock for REST tests. The tutorials and examples I've found all use RESTClient.
However I'm getting stuck with not being able to resolve RESTClient. The examples use import groovyx.net.http.RESTClient
. According to the examples this RESTClient seems like it should be included in org.codehaus.groovy.modules.http-builder
, which I've found in the MVN repository at https://mvnrepository.com/artifact/org.codehaus.groovy/http-builder/0.4.1.
0.4.1 seems to be the most recent version available there.
This is my build.gradle
:
plugins {
id 'groovy'
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.codehaus.groovy:groovy-all:3.0.8'
implementation 'org.codehaus.groovy:http-builder:0.4.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
testImplementation 'org.spockframework:spock-core:2.0-groovy-3.0'
}
test {
useJUnitPlatform()
}
The import seems to find groovyx.net.http
, but the code completion shows that there is no RESTClient in there.
I also found an example Groovy:unable to resolve class groovyx.net.http.RESTClient which seem to be using org.codehaus.groovy:http-builder:0.7
, but the http://repository.codehaus.org/
isn't online anymore. When I insist on getting version 0.7, which I found is possible by using the solution suggested at building oozie: Unknown host repository.codehaus.org, then the IntelliJ editor doesn't even find groovyx
(it is highlighted red).
I have to assume that the examples for making REST calls in Groovy that I found are showing obsolete material. Therefore the question is, what is the current best practice for making a REST call in Groovy? And in case it still is RESTClient, how can I get it to work?
I think you want this dependency, which is available on Maven Central: https://search.maven.org/artifact/org.codehaus.groovy.modules.http-builder/http-builder/0.7.1/jar
<dependency>
<groupId>org.codehaus.groovy.modules.http-builder</groupId>
<artifactId>http-builder</artifactId>
<version>0.7.1</version>
<scope>test</scope>
</dependency>
Sorry, I am a Maven user. In Gradle terms that probably translates to:
testImplementation 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
The library contains groovyx.net.http.RESTClient
.