How to correctly exclude "junit-vintage-engine" in Gradle build file?

5.5k views Asked by At

When use this configuration I receive the initializationError of the JUnit Vintage:

testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'

But with this configuration @RunWith annotation isn't resolved:

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

How can I correctly exclude the JUnit Vintage module?

2

There are 2 answers

0
Davi Diório Mendes On

It seems that for exclude you don't use group and name as parameters. You use group and module:

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

And as already pointed by Bjørn Vester you don't need to specify the version.

0
Bjørn Vester On

You just need to remove the version number from the exclude specification (as that would exclude a particular version that is not used anyway):

dependencies {
  implementation 'org.springframework.boot:spring-boot-starter'
  testImplementation('org.springframework.boot:spring-boot-starter-test') {
    exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' // <- No version
  }
}

test {
  useJUnitPlatform()
}