Netbeans Maven Project: How to Add a Dependency of Both Dependencies and Test Dependencies?

I have a Maven project in Netbeans 7.1 IDE.

I would like to add the same dependency to both Dependencies and Test Dependencies .

Adding to one removes it from another.

Duplication of dependency in pom.xml and inclusion in one of them:

 <scope>test</scope> 

.. doesn't work either.

Help!

More details:

Suppose I have MyProject and MyDependency .

MyProject contains MyDependency as the default scope (i.e., the compile scope):

 <dependencies> <dependency> <groupId>my.group.id</groupId> <artifactId>AnArtifactId</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> 

MyProject contains several classes in the Source Packages folder (i.e. MyProject/src/main/... ) that reference the MyDependency source classes. They work fine; Netbeans does not display red error flags, and these classes compile successfully.

MyProject contains several classes in the Test Packages folder (i.e. MyProject/src/test/... ) that reference the MyDependency test classes. Netbeans displays red error flags in MyProject for these links.

MyDependency been cleaned, built, and saved to the local Maven repository using mvn clean install -DskipTests . Running the same command for MyProject causes errors only in test classes; non-test classes compile fine.

+4
source share
2 answers

I found that the solution is to duplicate the pom dependency record as follows:

 <dependencies> <dependency> <groupId>my.group.id</groupId> <artifactId>AnArtifactId</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>my.group.id</groupId> <artifactId>AnArtifactId</artifactId> <version>1.0-SNAPSHOT</version> <scope>test</scope> <type>test-jar</type> </dependency> </dependencies> 

Specifying a single <scope>test</scope> means that the jar containing the original MyDependency packages should be used as a dependency for MyProject test packages.

However, by specifying <type>test-jar</type> , a test jar (that is, a jar containing test packets) for MyDependency used as a dependency for MyProject test packets.

+2
source

Dependencies also automatically Test Dependencies , but not vice versa.

0
source

Source: https://habr.com/ru/post/1396489/


All Articles