在maven中构建模块时如何构建依赖项目 [英] How to build dependent project when building a module in maven

查看:282
本文介绍了在maven中构建模块时如何构建依赖项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果通过maven构建子项目,我如何构建依赖项目。作为一个例子,我有2个项目叫做A,B。项目B依赖于项目A.当我用maven构建项目B时,我想建立项目A.我应该怎么做?

How can I build the dependent projects when a child project is getting build by maven. As an example, I have 2 projects call A,B. Project B is depending on project A. I want to build the project A when I am building project B with maven. How should I do it?

推荐答案

看看可以传递给mvn的这些选项:

Take a look at these options that can be passed to mvn:

Options:
 -am,--also-make                        If project list is specified, also
                                        build projects required by the
                                        list
 -amd,--also-make-dependents            If project list is specified, also
                                        build projects that depend on
                                        projects on the list

我相信你的情况你必须使用-amd

I believe in you case you have to use -amd

编辑:
如果您需要通过pom进行操作。
你只需要创建另一个模块,说C,只列出子模块A和B.
当你构建C时,maven反应器将自动构建两者。

In case you need to do it through a pom. You just need to create another module say C, that just lists the sub modules A and B. And when you build C, the maven reactor will automatically build both.

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>ParentModuleC</artifactId>
  <packaging>pm</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>ParentModuleC</name>
  <dependencies>
  </dependencies>
  <build>
  </build>
  <modules>
    <module>ModuleA</module>
    <module>ModuleB</module>
  </modules>
</project>

在ModuleA和B中,您需要添加以下内容:

In the ModuleA and B you need to add this:

<parent>
    <groupId>com.test</groupId>
    <artifactId>ParentModuleC</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

您的目录结构如下所示:

And your directory structure will look like this:

ParentModuleC
    |-pom.xml
    |----------->ModuleA
    |               |->pom.xml
    |----------->ModuleB
    |               |->pom.xml

看一下这个简单的例子:
http://books.sonatype.com/mvnex-book/reference/multimodule.html

Have a look at this for a simple example: http://books.sonatype.com/mvnex-book/reference/multimodule.html

这篇关于在maven中构建模块时如何构建依赖项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆