I have a Maven project in Netbeans 7.1 IDE.
I'd like to add the same dependency to both Dependencies
and Test Dependencies
.
Adding to one removes it from the other.
Duplicating the dependency in pom.xml and including in one of them:
<scope>test</scope>
..doesn't work either.
Help!
More Details:
Assume I have projects MyProject
and MyDependency
.
MyProject
contains MyDependency
as a default scope (ie compile
scope) dependency:
<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 (ie MyProject/src/main/...
) which reference classes within MyDependency
source packages. These work perfectly; Netbeans shows no red error flags and those classes compile successfully.
MyProject
contains several classes in the Test Packages
folder (ie MyProject/src/test/...
) which reference classes within MyDependency
test packages. Netbeans displays red error flags in MyProject
for these references.
MyDependency
has been cleaned, built and stored in local Maven repo using mvn clean install -DskipTests
. Running the same command for MyProject
causes errors within the test classes only; the non-test classes compile fine.
I discovered the solution is to duplicate the pom dependency entry 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 solely <scope>test</scope>
would indicate that the jar containing source packages of MyDependency
should be used as a dependency for the test packages of MyProject
.
However, by specifying <type>test-jar</type>
the test jar (ie jar containing test packages) for MyDependency
is used as a dependency for the test packages of MyProject
.
Dependencies
也自动是Test 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.