I have 3 independent projects in my main project. When I want to add the dependencies of these projects to main project, then first I am building the dependent projects and then finally building the main project. Is there is a way to build the dependent projects at the tim开发者_开发百科e of building the main project?
Sure, use a multi-module project
<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</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>someName</artifactId>
<name>someName</name>
<packaging>pom</packaging>
<modules>
<module>dependentProject1</module>
<module>dependentProject2</module>
<module>mainProject</module>
</modules>
</project>
In this comment you specified your question a bit clearer: "My problem is when i am building the project C then the projects A and B are also to be build and their dependencies should be added at the time of C build process only". You have dependencies, want to build the dependencies on building the project, but you do not want to use a multi-module project.
Want you want to do is not possible. I had a similar question, and found this clear answer this answer. Most other answers and comments suggest to have a multi project structure or to orchestrate the different (independent) builds with an ant script.
Can you explain better your situation (include the pom.xml)...maybe what you need is this http://docs.codehaus.org/display/MAVENUSER/Multi-modules+projects
In child project you can add
<groupId>com.childproj.service</groupId>
<artifactId>A</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
And in parent project you can do like
<dependencies>
<dependency>
<groupId>com.childproj.service</groupId>
<artifactId>A</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
精彩评论