java.lang.NoSuchMethodError with Junit5 in SpringBoot app

1.2k Views Asked by At

I was attempting to add some Parameterized unit tests to an app that I'm adding some enhancements to, but ran in to errors when attempting to launch JUnit once I added @Parameterized tests. I've found quite a few results similar to my issue that appear to be related to conflicting junit jars being pulled into the project. I've tried adding suggested jars from various posts, and this is the exception I currently get when I try to run a test class:

Caused by: java.lang.NoSuchMethodError: org.junit.platform.engine.TestDescriptor.getAncestors()Ljava/util/Set;
    at org.junit.platform.launcher.core.StackTracePruningEngineExecutionListener.getTestClassNames(StackTracePruningEngineExecutionListener.java:50)

This app was using Gradle 5.6.4, I've since updated it locally to use 6.8.3 due to a message I received in my console once I added newer Junit5 jars.

Here is my current build.gradle file (irrelevant parts removed for brevity):

plugins {
    id 'org.springframework.boot' version '2.7.15'
    id 'io.spring.dependency-management' version '1.1.3'
    id 'java'
}

apply plugin: 'maven-publish'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-ldap'
    implementation 'org.springframework.security:spring-security-ldap'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.retry:spring-retry:1.3.0'
    implementation 'org.hibernate:hibernate-java8'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'org.projectlombok:lombok:1.18.12'

    //Swagger
    implementation 'io.springfox:springfox-swagger2:2.6.1'
    implementation 'io.springfox:springfox-swagger-ui:2.6.1'

    annotationProcessor 'org.projectlombok:lombok:1.18.12'

    developmentOnly 'org.springframework.boot:spring-boot-devtools'

    runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
    runtimeOnly 'com.ibm.db2:jcc'

    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
    testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.0'
    testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0'
    implementation 'org.junit.platform:junit-platform-commons:1.10.0'
    testImplementation  'org.junit.platform:junit-platform-launcher:1.10.0'

    testImplementation 'commons-dbcp:commons-dbcp:1.4'
    testImplementation 'com.h2database:h2:1.4.200'

}

test {
    useJUnitPlatform()
}

For reference, here's what the build.gradle file looked like originally (I updated the spring boot and spring dependency management versions as well as updating/adding the Junit5 dependencies):

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

apply plugin: 'maven-publish'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-ldap'
    implementation 'org.springframework.security:spring-security-ldap'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.retry:spring-retry:1.3.0'
    implementation 'org.hibernate:hibernate-java8'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'org.projectlombok:lombok:1.18.12'
    implementation 'org.junit.jupiter:junit-jupiter-engine:5.6.2'

    //Swagger
    implementation 'io.springfox:springfox-swagger2:2.6.1'
    implementation 'io.springfox:springfox-swagger-ui:2.6.1'

    annotationProcessor 'org.projectlombok:lombok:1.18.12'

    developmentOnly 'org.springframework.boot:spring-boot-devtools'

    runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
    runtimeOnly 'com.ibm.db2:jcc'

    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'commons-dbcp:commons-dbcp:1.4'
    testImplementation 'com.h2database:h2:1.4.200'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.8.2'

}

test {
    useJUnitPlatform()
}

Any suggestions would be greatly appreciated!

0

There are 0 best solutions below