Java 无法解析方法';解析';在';DockerImageName';在JUnit5中使用Testcontainers和gradle时

Java 无法解析方法';解析';在';DockerImageName';在JUnit5中使用Testcontainers和gradle时,java,gradle,apache-kafka,testcontainers,Java,Gradle,Apache Kafka,Testcontainers,测试无法编译,错误为无法解析“DockerImageName”中的方法“parse” @SpringBootTest @Testcontainers public class KafkaContainerTest { @ClassRule public static KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.2.1"));

测试无法编译,错误为
无法解析“DockerImageName”中的方法“parse”

@SpringBootTest
@Testcontainers
public class KafkaContainerTest {
    @ClassRule
    public static KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.2.1"));

    @Test
    public void testUsage() throws Exception {
            kafka.start();
            testKafkaFunctionality(kafka.getBootstrapServers());
    }
//...
}
build.gradle

plugins {
    id 'org.springframework.boot' version '2.3.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: '2.3.4.RELEASE'
    implementation 'org.apache.kafka:kafka-streams'
    implementation 'org.springframework.kafka:spring-kafka'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    testCompile 'org.projectlombok:lombok'
    testCompile group: 'io.projectreactor', name: 'reactor-test', version: '3.3.10.RELEASE'
    testImplementation 'io.projectreactor:reactor-test'
    testImplementation 'org.springframework.kafka:spring-kafka-test'
    testImplementation 'com.google.guava:guava:23.0'
    testImplementation 'org.testcontainers:testcontainers:1.14.3'
    testImplementation "org.testcontainers:junit-jupiter:1.14.3"
    testImplementation 'org.testcontainers:kafka:1.14.3'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}
在IntelliJ中导航到
DockerImageName
类时,会显示
库源与类DockerImageName
的字节码不匹配。没有帮助

更新

plugins {
    id 'org.springframework.boot' version '2.3.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: '2.3.4.RELEASE'
    implementation 'org.apache.kafka:kafka-streams'
    implementation 'org.springframework.kafka:spring-kafka'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    testCompile 'org.projectlombok:lombok'
    testCompile group: 'io.projectreactor', name: 'reactor-test', version: '3.3.10.RELEASE'
    testImplementation 'io.projectreactor:reactor-test'
    testImplementation 'org.springframework.kafka:spring-kafka-test'
    testImplementation 'com.google.guava:guava:23.0'
    testImplementation 'org.testcontainers:testcontainers:1.14.3'
    testImplementation "org.testcontainers:junit-jupiter:1.14.3"
    testImplementation 'org.testcontainers:kafka:1.14.3'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}
这很有效

testImplementation 'org.testcontainers:testcontainers:1.15.0-rc2'
testImplementation "org.testcontainers:junit-jupiter:1.15.0-rc2"
testImplementation 'org.testcontainers:kafka:1.15.0-rc2'

静态
parse
方法仅在7月份添加到
testcontainers
库中。您使用的是5月份发布的版本
1.14.3
。我希望如果您将库的版本升级到
15.X
(版本
1.15.0-rc2
似乎是最新的),我希望您的问题会得到解决

或者,您可以将该库的使用更改为版本
1.14.3
中的功能

更新:我刚刚看到(并最终理解)@tgdavies的建议,您可以通过以下方式直接调用
dockeriagename
对象的构造函数:

return new DockerImageName(fullImageName);

什么是
dockeriagename
?不管它是什么,它显然没有
parse()
方法,因此您的代码在语法上是不正确的,因为您试图在该对象上调用这样的方法如中所建议,我同意您在那里打了一个正确的电话。必须是该类没有定义,或者定义为您正在显示的内容以外的内容。该类的
import
语句是什么样子的?我希望在文件的顶部有一个,如果查看源代码,它所做的就是
publicstaticdockeriagename解析(stringfullimagename){returnnewdockeriagename(fullImageName);}
(当然,这在将来可能会改变,因此最好调用静态方法,但如果不想转到rc,只创建实例是可以接受的解决方法。)@tgdavies-不想从你那里窃取分数或其他任何东西…只是想让这个问题有一个真正的答案。我自己过来想得到答案,但你在我面前。如果你想获得这方面的荣誉,只需复制我的答案并粘贴为新答案,或者创建一个你自己的答案,我会删除我的答案。