groovyx.net.http 缺少 RESTClient

groovyx.net.http is missing RESTClient

我正在尝试了解如何使用 Spock 进行 REST 测试。我找到的教程和例子都是用RESTClient的。

但是我无法解析 RESTClient。这些示例使用 import groovyx.net.http.RESTClient。根据示例,这个 RESTClient 似乎应该包含在 org.codehaus.groovy.modules.http-builder 中,我在 https://mvnrepository.com/artifact/org.codehaus.groovy/http-builder/0.4.1.

的 MVN 存储库中找到了它

0.4.1 似乎是那里可用的最新版本。 这是我的 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()
}

导入好像找到了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 ,然后IntelliJ编辑器甚至没有找到groovyx(它以红色突出显示)。

我必须假设我发现的 Groovy 中进行 REST 调用的示例显示已过时 material。因此问题是,在 Groovy 中进行 REST 调用的当前最佳实践是什么?如果它仍然是 RESTClient,我怎样才能让它工作?

我想你需要这个依赖项,它在 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>

抱歉,我是 Maven 用户。在 Gradle 术语中可能转化为:

testImplementation 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'

图书馆包含groovyx.net.http.RESTClient