0

I'm trying to use Powermock in my project, but when I add the import to a test class, it doesn't work. it get the The import org.powermock cannot be resolved. I have it added it to my pom.xml as below. I can also see it in my Project Explorer as per the screenshot. Any ideas why it doesn't work?

The most annoying thing is that I can Ctrl-Click it to go to the source class in the Maven Dependency linked folder, and yet it still complains.

   <dependencies>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>1.10.19</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>1.6.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4-common</artifactId>
            <version>1.6.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>1.6.6</version>
            <scope>test</scope>
        </dependency>
   </dependencies>

enter image description here

Mox
  • 564
  • 2
  • 8
  • 20
  • Is it in `~/.m2/repository`? That's usually the only place that Maven looks for artifacts. – Makoto Jun 08 '21 at 20:06
  • Do you have a `module-info.java` file? Please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) and tell the Eclipse version. – howlger Jun 08 '21 at 20:08
  • @Makoto It is there, yep. :/ – Mox Jun 08 '21 at 20:26
  • Try to run `mvn clean install`, then refresh your IDE. – Harry Coder Jun 09 '21 at 06:05
  • Such an error is displayed, for example, when the class is located in a source folder that does not have the test scope (dependencies and source folders with test scope are displayed darker). Unfortunately, this and other information is missing in your question, so that one could help you. It seems that you are assuming that it is a bug of Eclipse, which is very unlikely if you are using a recent version where no such problems are known. – howlger Jun 09 '21 at 06:12
  • @HarryCoder Tried that many times. `mvn clean install -U`, then in Eclipse Refresh, Clean and Build All, Maven -> Update Project.... To no avail. :( – Mox Jun 09 '21 at 08:10
  • Try to clean your project `Project > Clean` or delete the `jar` dependency in your maven repository and rebuild your project with `mvn clean install -U`. For more details follow this link : https://stackoverflow.com/questions/4322893/eclipse-error-the-import-xxx-cannot-be-resolved – Harry Coder Jun 09 '21 at 12:37

1 Answers1

0

Right click on the project -> Build Path -> Configure Build Path. Check if Maven dependencies are available under build path. If not add them manually and check.

enter image description here