开发者

In Maven How to build the dependent projects that are added as the dependencies in the main project when building the main project?

开发者 https://www.devze.com 2023-03-16 08:01 出处:网络
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 m

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>

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号