【问题标题】:build multiple modules multiple times in parent pom在父 pom 中多次构建多个模块
【发布时间】:2016-02-08 22:01:16
【问题描述】:

需要从多个模块构建和打包多个应用程序。

在父 pom 中,我使用配置文件为不同的应用调用构建。

root
  parent/
     pom.xml
  moduleA/
     pom.xml
  moduleB/
     pom.xml
  moduleC/
     pom.xml

例如,应用程序“profile-1”需要构建现有模块的子集并将其组合成一个 tar 球。 tar 将包含几个 jars 和从子模块的 target/ 中提取的不同配置文件。

我正在使用一个使用 exec-maven-plugin 调用的 shell 脚本来组合 tar。

我面临的问题是,在一个应用程序中,我需要多次构建同一个模块,但使用不同的 maven 参数。

最好的方法是什么?

<profiles>
        <profile>
            <id>profile-1</id>
            <modules>
                <module>../moduleA</module>
                <module>../moduleB</module>
                <!-- <module>../moduleC</module> -->
            </modules>
            <properties>
                <global.version>0.0.1-SNAPSHOT</global.version>
            </properties>
            <build>
                <!-- use maven exec plugin to run a shell script which generates the tar ball picking jars and config files from different modules target dirs -->
                <plugins>
                </plugins>
            </build>
        <profile>
</profiles>

一个示例子模块 pom

<groupId>com.test</groupId>
    <artifactId>moduleC</artifactId>
    <packaging>bundle</packaging>
    <version>${global.version}</version>

    <name>test :: ${project.artifactId} :: ${name} </name>


    <parent>
      <groupId>com.test</groupId>
      <artifactId>parent</artifactId>
      <version>${global.version}</version>
      <relativePath>../parent</relativePath>
    </parent>

我尝试过的事情:
1) 我可以分成多个配置文件并将它们作为-Pprofile-1,profile-2 调用吗?
它对我不起作用,但我会做错事。

2) 有另一个带有 mvn 命令行的 shell 脚本以不同的方式构建 moduleC。
- 即使我传入“-Dglobal_version”,从 mvn 命令行运行的 moduleC 似乎也没有在存储库中找到父级。

我尝试在构建应用程序之前进行“-N”构建以将父 pom 放入存储库,但没有帮助。

【问题讨论】:

  • “我正在使用一个使用 exec-maven-plugin 调用的 shell 脚本来组合 tar。”。这是一个很大的迹象,表明你在某处做错了什么。组装通常使用maven-assembly-plugin 完成。为什么你有这么多个人资料?这也是你构建中的一种气味。
  • 我可以使用程序集插件。我需要构建和打包使用子模块的不同组合组合在一起的不同应用程序。但是如何通过传入不同的 maven 参数来多次构建同一个模块?

标签: maven build maven-3 build-process


【解决方案1】:

最好的办法是:

mvn clean install --projects moduleA, moduleB
mvn clean install --projects moduleB, moduleC

您不能使用 maven (see this stackoverflow question) 运行多个构建

【讨论】:

    猜你喜欢
    • 2010-12-09
    • 2012-04-13
    • 2013-02-23
    • 1970-01-01
    • 2012-02-06
    • 2011-10-29
    • 1970-01-01
    • 1970-01-01
    • 2015-01-31
    相关资源
    最近更新 更多