klippy
klippy

Reputation: 243

Why am I getting this NoClassDefFound error?

I am trying to create a contract in Spring(https://spring.io/projects/spring-cloud-contract)

This is the error I keep getting:

Tests in error: ContractVerifierTest.validate_shouldReturnPreviousAddress:19 » NoClassDefFound

And this is the line causing the problem:

// given:
MockMvcRequestSpecification request = given();

This is my groovy file:

package contracts

import org.springframework.cloud.contract.spec.Contract


Contract.make {

    request {
        method 'GET'
        url value(consumer('/echo'), producer('/echo'))
    }
    response {
        status 200
        headers {
            header(
                    'Content-Type', value(consumer('text/plain;charset=ISO-8859-1'), producer(regex('text/plain;charset=ISO-8859-1')))
            )
        }
        body(
                "Send me something!"
        )
    }
    priority 1
}

And I have included the following in my pom file:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-contract-maven-plugin</artifactId>
            <version>1.2.2.RELEASE</version>
            <extensions>true</extensions>
            <configuration>
            <baseClassForTests>[baseClass link]</baseClassForTests>
            </configuration>
        </plugin>
    </plugins>
</build>

As far as I can see, the line causing this problem is correct. Is there something else I could be missing?

EDIT:

On closer inspection, this seems to be the real cause of the issue:

java.lang.NoClassDefFoundError: io/restassured/internal/common/assertion/AssertParameter

Upvotes: 0

Views: 577

Answers (1)

Amit
Amit

Reputation: 669

java.lang.NoClassDefFoundError

The above error usually happens due to a mismatch between Spring Cloud and Spring Boot versions or outdated dependencies.

Spring Cloud releases are tied to specific Spring Boot versions. One can refer the following table in the Spring Cloud documentation:

Release train Spring Boot compatibility

Release Train Boot Version
2021.0.x aka Jubilee 2.6.x, 2.7.x (Starting with 2021.0.3)
2020.0.x aka Ilford 2.4.x, 2.5.x (Starting with 2020.0.3)
Hoxton 2.2.x, 2.3.x (Starting with SR5)
Greenwich 2.1.x
Finchley 2.0.x
Edgware 1.5.x
Dalston 1.5.x

Note: It is recommended to use rest-assured that comes out of the box with Spring, to avoid any version mismatches.

Upvotes: 0

Related Questions