Resolve maven dependencies from child pom

时间:2015-06-25 18:36:21

标签: java maven

I'm quite new to maven and I have a maven multi module project with the parent pom as

 <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.test.cit</groupId>
  <artifactId>cit</artifactId>
  <version>LATEST-SNAPSHOT</version>
  <name>Integration Test Framework</name>
  <packaging>pom</packaging>
  <modules>
            <module>common</module>
            <module>core</module>
            <module>login</module>
  </modules>
</project>

I have put all the relevant external dependencies to the child poms of common, core and login. I then converted the project to an eclipse project (mvn eclipse:eclipse) and after that eclipse is unable to resolve the dependencies in the child pom though the respective jars are present in M2_HOME.

I then added all the dependencies to the parent pom(Whatever dependency was there in the child poms) from the child poms and then eclipse was able to resolve that.

I'm confused of this behavior. Since I've already added the external dependencies to the child poms why should I add again that to the parent pom?

Anybody could you please explain this or am I doing something wrong here to fix the problem.

1 个答案:

答案 0 :(得分:2)

In the parent pom you have the option to add two tags : <dependencies></dependencies> and <dependencyManagement></dependencyManagement> In the <dependencies> tag you have to place all the dependencies that you want that all you projects includes, for example JUnit dependency or Log4j. In the <dependencyManagement> tag you should add all the dependencies that your project needs, It does not means that they are going to be included in all your projects. It only means that your child projects can include them or not. It is going to help you to manage the versions. Maybe you have problems in the dependency bewteen your child projects for this reason when you add all the dependencies to your parent project It works.