【问题标题】:How to correctly exclude "junit-vintage-engine" in Gradle build file?如何在 Gradle 构建文件中正确排除“junit-vintage-engine”?
【发布时间】:2020-10-04 17:44:06
【问题描述】:

使用此配置时,我会收到 JUnit Vintage 的 initializationError:

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 模块?

【问题讨论】:

    标签: gradle junit junit4 junit5 junit-vintage


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      似乎排除您不使用组和名称作为参数。你使用组和模块:

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

      正如 Bjørn Vester 已经指出的那样,您不需要指定版本。

      【讨论】:

        猜你喜欢
        • 2020-03-30
        • 2017-06-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-11
        • 2014-03-18
        • 2016-07-06
        • 1970-01-01
        相关资源
        最近更新 更多