我试图运行一个简单的maven项目,由父pom和(一个或多个)子项目组成。孤立地运行每个子项非常有用,但是当我添加<parent>
数据时,子项目不会解析依赖项。
当我运行$mvn test
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[...]symbol: class TestCase
[...]services\TikalWebServiceTest.java:[3,22] package junit.framework does not exist
[...]services\TikalWebServiceTest.java:[4,22] package junit.framework does not exist
在子项目中,我pom.xml
声明了junit依赖
<parent>
<artifactId>myapp</artifactId>
<groupId>com.some.app</groupId>
<version>1.0.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
[................]
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
在我的父项目中,我还包括了这个依赖项,还有一些回购信息
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
effective-pom
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>