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

当子项目由 maven 构建时,我如何构建依赖项目。例如,我有 2 个名为 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 reactor 会自动构建两者。

<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 中你需要添加这个:

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

您的目录结构将如下所示:

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

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

https://stackoverflow.com/questions/25480598/

相关文章:

ios - 无法运行 faSTLane 叹息。 "Couldn' t下载证书"

c++ - 尝试构建 boost 时更新 58 个目标失败,发生了什么?

java - 目前是否可以通过 Maven 构建 Eclipse 插件并具有良好的 IDE 集成?

android - 使用 gradle 为不同的应用程序风格使用不同的资源

unit-testing - 在 Visual Studio 中进行单元测试时会重建不必要的项目

javascript - 为什么我要同时使用 TypeScript 和 Babel?

visual-studio - 在构建期间无法自动将 NuGet 包更新到最新版本

.net - NuGet Enterprise - 不同成熟度级别包的最佳实践

xcode - 如何在 Xcode 4 的运行脚本构建阶段中使用 sudo?

javascript - Bower 和 NPM 如何结合在一起?