在maven中构建模块时如何构建依赖项目

在maven中构建模块时如何构建依赖项目,maven,build,dependencies,Maven,Build,Dependencies,当一个子项目由maven构建时,如何构建依赖项目。例如,我有两个项目称为A,B。项目B取决于项目A。我想在使用maven构建项目B时构建项目A。我应该怎么做?看看这些可以传递给mvn的选项: Options: -am,--also-make If project list is specified, also build projects required by the

当一个子项目由maven构建时,如何构建依赖项目。例如,我有两个项目称为A,B。项目B取决于项目A。我想在使用maven构建项目B时构建项目A。我应该怎么做?

看看这些可以传递给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

编辑: 以防你需要通过pom来完成。 您只需要创建另一个模块,比如C,它只列出子模块A和B。 当你构建C时,maven反应堆会自动构建这两个

<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>
下面是一个简单的例子:

看看这些可以传递给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

编辑: 以防你需要通过pom来完成。 您只需要创建另一个模块,比如C,它只列出子模块A和B。 当你构建C时,maven反应堆会自动构建这两个

<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>
下面是一个简单的例子:

我可以用pom来做吗?编辑了如何使用多模块项目来做的答案。答案刚刚被指出是重复问题的答案()。对不起,这个答案不是很清楚
amd
在答案中引用,但未在依赖多模块概念的拟议解决方案中使用。您应该删除对
amd
的引用,或者解释为什么它不适用于这种情况,否则可能会产生误导。我可以用pom来做吗?编辑了关于如何使用多模块项目来做的答案答案。答案刚刚被指出为重复问题的答案()。对不起,这个答案不是很清楚
amd
在答案中引用,但未在依赖多模块概念的拟议解决方案中使用。您应该删除对
amd
的引用,或者解释为什么它在这种情况下不适用,否则可能会产生误导。