首页 > 解决方案 > 如何在 Gradle 构建文件中正确排除“junit-vintage-engine”?

问题描述

使用此配置时,我会收到initializationErrorJUnit Vintage:

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

@RunWith但是没有解决这个配置注释:

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

如何正确排除 JUnit Vintage 模块?

标签: gradlejunitjunit4junit5junit-vintage

解决方案


您只需要从排除规范中删除版本号(因为这将排除无论如何都不使用的特定版本):

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()
}

推荐阅读