【发布时间】:2018-07-30 19:17:11
【问题描述】:
我收到了错误 java: package org.hamcrest does not exist。
POM 文件如下所示:
<dependencies>
...
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
在一些测试中,我有这个导致错误的导入:
import static org.hamcrest.CoreMatchers.*;
我正在使用 IntelliJ 2017.3.4
我尝试删除scope 标签并将其更改为compile,并导入其他hamcrest 包,如hamcrest.core。此外,运行 mvn clean 并重建项目也不起作用。
【问题讨论】:
-
这些依赖包是否包含在
<dependencyManagement/>中? -
不,它们在
<project>标签内 -
你在使用mockito吗? Mockito 将自己的
org.hamcrest包打包到 lib 中。我记得,这个包也曾经是 JUnit 的一部分,不知道它是否仍然存在问题。尝试将您的 hamcrest-all 依赖项定义移动到dependencies部分的首位(在 mockito 和 junit 依赖项之前) -
@Bedla 我没有使用 Mockito。在 JUnit 之前移动包没有任何区别。