gpt4 book ai didi

Maven 错误 - 包 org.junit 不存在

转载 作者:行者123 更新时间:2023-11-28 20:23:24 25 4
gpt4 key购买 nike

我在使用 maven 和 junit 时遇到了一些麻烦。单独运行 junit 测试完美无缺,但使用 Maven mvn clean test 构建失败。我确保所有测试都在“src/test/java”中,所有源都在“src/main/java”中,所以 junit 可以找到它们(关于其他问题,这是许多其他情况下的问题)。

那么有人知道为什么这对我不起作用吗?

截取的错误信息:

/D:/pathToProject/myProject/src/test/java/myPackage/MyFile.java:[5,17] package org.junit does not exist

Pom.xml 片段:

<...project information.../>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source />
<target />
</configuration>
</plugin>
</plugins>
<plugins>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

最佳答案

Khmarbaise 向您指出了一个错误,您覆盖了 src 目录这一事实意味着 Maven 将尝试在 compile 阶段编译您的测试类,但会失败,因为您的 jUnit 依赖项以 test 范围给出,在 test phase 中可用只有稍后出现的

要么删除范围“测试”,要么更改您的源目录位置,使其不包含您的测试类

关于Maven 错误 - 包 org.junit 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28173431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com