【问题标题】:Found used undeclared dependencies junit 4.13 when I use junit 5当我使用junit 5时发现使用了未声明的依赖项junit 4.13
【发布时间】:2020-06-25 06:44:44
【问题描述】:

我正在从 junit 4 迁移到 junit 5。我在分析依赖项时遇到了问题。 当我运行 mvn dependency:analyze 时,出现错误:

[WARNING] Used undeclared dependencies found:
[WARNING]    junit:junit:jar:4.13:test
[INFO] Add the following to your pom to correct the missing dependencies: 
[INFO] 
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.13</version>
  <scope>test</scope>
</dependency>

我的 pom.xml

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
          <execution>
            <id>analyze</id>
            <goals>
              <goal>analyze-only</goal>
            </goals>
            <configuration>
            <ignoredDependencies>
              <ignoredUsedUndeclaredDependencies>junit:junit:jar:4.13</ignoredUsedUndeclaredDependencies>
            </ignoredDependencies>
            </configuration>
          </execution>
        </executions>
      </plugin>

<dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-launcher</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.vintage</groupId>
      <artifactId>junit-vintage-engine</artifactId>
      <scope>test</scope>
    </dependency>

请帮助我们消除此错误

【问题讨论】:

    标签: java maven testing junit


    【解决方案1】:

    使用的未声明依赖项是必需的,但尚未在项目中明确声明为依赖项。直接声明使用的依赖而不依赖传递依赖是一种很好的风格。这不是问题,只是不太好。

    您应该调查一下,您的代码的哪些部分使用了 JUnit 4 代码。为了使搜索更容易,您可以暂时排除它:

    https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

    由于您在示例中没有显示任何版本,因此我无法确定传递依赖项来自何处,因此无法确定排除项的位置。

    【讨论】:

    • 这个依赖用在 org.junit.vintage:junit-vintage-engine:jar:5.6.2:test 我使用了命令 mvn dependency:tree 我得到了下面的依赖树 \- org.junit.vintage:junit-vintage-engine:jar:5.6.2:test \- junit:junit:jar:4.13:test
    • JUnit 老式引擎的目的是支持旧的 JUnit 3/4 测试。 - 如果您没有它们,请摆脱老式引擎。 - 如果您有它们,请按照错误消息中的说明声明对 JUnit 4.13 的依赖。
    • 我添加了 junit 4.13 依赖项 - 错误未重现。我想我应该添加一个老式依赖项并删除 junit 4.13。谢谢你的回答。
    猜你喜欢
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-17
    • 2021-07-07
    • 2016-08-03
    • 2019-08-15
    • 2017-07-31
    相关资源
    最近更新 更多