Gradle 5 JUnit BOM and Spring Boot Incorrect Versions

前端 未结 3 1554
星月不相逢
星月不相逢 2020-11-28 14:04

I am using Gradle 5\'s BOM (Bill of Materials) feature. This is how I describe it for my JUnit 5 dependencies:

testImplementation(enforcedPlatform(\"org.juni         


        
相关标签:
3条回答
  • 2020-11-28 14:10

    Ensure to include JUnit's BOM before other BOMs that also refer to JUnit. First BOM wins and locks version of all later artifacts.

    See this issue for a similar setup using Maven and Spring Boot: https://github.com/sormuras/junit-platform-maven-plugin/issues/29#issuecomment-456958188

    0 讨论(0)
  • 2020-11-28 14:17

    JUnit 5.4.0 simplified its artifacts, and now delivered a single artifact for Jupiter - org.junit:junit-jupiter. I.e., you should simplify your Gradle file too:

    testImplementation(enforcedPlatform("org.junit:junit-bom:5.4.0")) // JUnit 5 BOM
    testImplementation("org.junit.jupiter:junit-jupiter")
    
    0 讨论(0)
  • 2020-11-28 14:29

    How do I disable JUnit coming from the Gradle Spring Dependency Management plugin?

    For starters, if you are using the dependency management plugin from Spring, you should not be importing the junit-bom since that results in duplicate (and potentially conflicting) management of those dependencies.

    Aside from that, whenever you use the dependency management plugin from Spring and want to override a managed version, you have to do it by overriding the exact name of the version defined in the BOM used by the plugin.

    This is documented in Spring Boot for Gradle and for Maven.

    For Spring Boot the name of the JUnit Jupiter version is "junit-jupiter.version". You can find the names of all managed versions for Spring Boot 2.1.2 here.

    So, in Gradle you would override it as follows.

    ext['junit-jupiter.version'] = '5.4.0'.

    You can see that I have done exactly that here.

    With Maven you would override it as follows.

    <properties>
        <junit-jupiter.version>5.4.0</junit-jupiter.version>
    </properties>
    

    Further background information here: https://docs.spring.io/platform/docs/current/reference/html/getting-started-overriding-versions.html

    0 讨论(0)
提交回复
热议问题