Problem: Maven can't find some dependencies inside my tests
import org.hamcrest.core.StringStartsWith; // HIGHLIGHTED AS RED IN INTELLIJ
It's imported like this in my pom.xml:
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
I already tried:
The way to figure this out is to run your tests from the command line, via mvn verify
, and ensure that things compile and run correctly. This will allow you to determine whether the problem is in your POM configuration, or something unique to Intellij.
If it's a problem in Intellij, it is very likely to be something around folder configuration: generally only folders marked as "Test Source Root" will have access to things in the test scope.
确保至少在<project><dependencies>
下的<project><dependencies>
下指定<project><dependencyManagement><dependencies>
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.