Reputation: 710
I created a pom.xml that includes the XML to import JUnit 4. I opened up project in IntelliJ. It seems to have downloaded the external dependency, but when I try to use the dependency in an import statement, IntelliJ can't recognize it.
Here are the steps I took from the beginning:
I believe that Maven imported everything correctly because I can see JUnit as a dependency in the project directory: https://imgur.com/TdJq7PK
Here is my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.org</groupId>
<artifactId>mvn-prac</atifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
When I attempt to use a common class from JUnit, such as import org.junit.Test;
, IntelliJ can't recognize the symbol.
I have attempted both mvn clean
and mvn install
in the root of the project, and neither seemed to help.
Thanks for any help.
Upvotes: 1
Views: 286
Reputation: 401897
If you are using the test
scope, JUnit dependency will be available only for the tests located in src/test/java
, but not to the classes in src/main/java
.
Either remove the <scope>test</scope>
line in pom.xml
or move your tests to the proper Test Sources root.
Upvotes: 1