Cannot resolve method 'parse' in 'DockerImageName' when using Testcontainers and gradle in JUnit5

3.9k Views Asked by At

The test fails to compile with error 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()
}

When navigating to DockerImageName class in IntelliJ it says Library source does not match the bytecode for class DockerImageName. This answer did not help.

Update

This works

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'
1

There are 1 best solutions below

0
On BEST ANSWER

The static parse method was only added to the testcontainers library back in July. You're using version 1.14.3, which was released in May. I expect that if you upgrade the version of the library to a 15.X (version 1.15.0-rc2 seems to be the latest), I expect your problem will be resolved.

Alternately, you can change your usage of that library to what it was capable of in version 1.14.3.

UPDATE: I just saw (and finally understood) @tgdavies's suggestion that you can just call the DockerImageName object's constructor directly via:

return new DockerImageName(fullImageName);