简体   繁体   中英

Maven: test dependencies

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:

  1. mvn test-compile
  2. Invalidate Intellij caches
  3. Restart Intellij
  4. Clear .m2 and rebuild project

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM