测试无法用错误的Cannot resolve method 'parse' in 'DockerImageName'编译
@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中导航到IntelliJ类时,它表示为Library source does not match the bytecode for class DockerImageName。This answer没有帮忙。
更新
这行得通
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'发布于 2020-10-17 21:01:09
静态parse方法仅在7月才添加到testcontainers库中。您正在使用的是1.14.3版本,它是在5月发布的。我希望如果您将库的版本升级到15.X ( 1.15.0-rc2版本似乎是最新版本),我希望您的问题将得到解决。
或者,您可以将该库的使用更改为它在1.14.3版本中所能做到的。
更新:我刚刚看到(并最终理解)@tgdavies的建议,您可以直接通过以下方式调用DockerImageName对象的构造函数:
return new DockerImageName(fullImageName);https://stackoverflow.com/questions/64407003
复制相似问题