【问题标题】:spring boot starter test 1.4.1 - use assertj-core 3.5.xspring boot starter test 1.4.1 - 使用assertj-core 3.5.x
【发布时间】:2017-03-22 15:21:24
【问题描述】:

我想为 Java8 使用最新的 assertj-core(例如在可选项上断言)。 我使用 spring-boot-starter-test 1.4.1,它带有预先配置的 assertj 2.5.0。

我不能使用 spring boot 父 pom。

如何设置我的 maven 项目,以便使用 3.5.2 排除或覆盖 2.5.0 版本?我试过了

  • 只设置属性assertj.version
  • starter-test dependency 上添加排除项
  • spring-boot-dependencies 上添加排除项

更新:

我正在为我的多模块项目中的所有模块设置一个自定义“测试”模块。我不仅需要 spring-test-starter,还需要一些其他依赖项和一些测试类和规则。

这是我的项目的样子:

my-module-root
 |-my-module-a (using test)
 |-my-module-b (using test)
 \-test (including starter-test, ... - in COMPILE scope (because this is a test library))

现在,当我在测试模块(并包括 3.5.2)上排除 assertj-core 时,测试模块的依赖关系正常。 但是当我检查根级别的依赖项时,我在类路径上同时拥有 assertj-core-2.5.0 和 assertj-core-3.5.2。

【问题讨论】:

  • 模块 A 和 B 是否在“测试”范围内包含模块测试?你确定你除了“test”模块之外没有包含任何spring-boot-starter-test?
  • 是的,是的。双重检查。我将在github上创建一个小样本来验证...

标签: maven spring-boot


【解决方案1】:

您可以将其从spring-boot-starter-test 中排除,然后手动添加不同的版本:

<dependencies>
    ...
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.assertj</groupId>
                <artifactId>assertj-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>3.5.2</version>
        <scope>test</scope>
    </dependency>
</dependencies>

验证包含哪个版本:

$ mvn dependency:tree | grep assertj
[INFO] \- org.assertj:assertj-core:jar:3.5.2:test

【讨论】:

  • 感谢您的更新。这就是我第二点的意思。这个已经试过了。忘记在问题中提及某些内容
猜你喜欢
  • 2019-03-22
  • 2020-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-28
  • 2014-04-07
  • 2017-07-30
  • 2021-01-22
相关资源
最近更新 更多