Wrong version of JUnit in dependencies

梦想的初衷 提交于 2020-06-01 03:15:53

问题


I want to run JUnit 5.4+ tests on my Spring Boot app so that I can use the @Order annotation on my tests. However, Maven resolves my POM to 5.3.2 regardless of what I try. I've tried including all the dependencies I can think of manually, but then I end up with a mess of mismatched versions. I also tried clearing my entire ~/.m2/repository folder and rebuilding the tree, same results.

Relevant parts of mvn dependency:tree

[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.5.0:test
[INFO] |  +- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] |  +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] |  \- org.junit.platform:junit-platform-commons:jar:1.3.2:test
[INFO] +- org.junit.jupiter:junit-jupiter:jar:5.5.0:test
[INFO] |  +- org.junit.jupiter:junit-jupiter-params:jar:5.3.2:test
[INFO] |  \- org.junit.jupiter:junit-jupiter-engine:jar:5.3.2:test
[INFO] |     \- org.junit.platform:junit-platform-engine:jar:1.3.2:test

Part of the pom.xml

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.5.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.5.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>
...
<plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
            </plugin>
...

Where does the 5.3.2 come from?


回答1:


Add this line to your the properties in your Maven pom.xml:

<junit-jupiter.version>5.5.0</junit-jupiter.version>

this will control the dependencies defined in dependency management within the spring boot poms (org.springframework.boot:spring-boot-dependencies).


The reason is: that org.springframework.boot:spring-boot-dependencies include junit-bom

  <dependency>
    <groupId>org.junit</groupId>
    <artifactId>junit-bom</artifactId>
    <version>${junit-jupiter.version}</version>
    <type>pom</type>
    <scope>import</scope>
  </dependency>

per default junit-jupiter.version is 5.3.2. So as long as you not change junit-jupiter.version, this bom will define that all not explicit listed dependencies (for example org.junit.jupiter:junit-jupiter-params) are of the version defined in org.junit:junit-bom:5.3.2



来源:https://stackoverflow.com/questions/57055534/wrong-version-of-junit-in-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!