【问题标题】:Maven pom.xml - Project AggregationMaven pom.xml - 项目聚合
【发布时间】:2011-03-13 10:41:01
【问题描述】:

我们设置了一个聚合 .pom,以包含多个单独的模块,类似于 Maven documentation

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
  <packaging>pom</packaging>

  <modules>
    <module>my-module</module>
    <module>my-module-2</module>
  </modules>
</project>

有没有办法在构建后从这两个模块的构建(.JAR 文件)中获取工件到一个公共的“dist”目录中?我不想调整“my-module/target”中各个模块的输出目录,因为它们也可以单独构建。

我是 Maven 新手,所以我确信有一种简单的方法可以做到这一点。

【问题讨论】:

    标签: maven-2 build pom.xml


    【解决方案1】:

    有没有办法在构建后从这两个模块的构建(.JAR 文件)中获取工件到一个通用的“dist”目录中?

    Maven Assembly Plugin 可以做到这一点,它非常强大和灵活。但功能和灵活性也意味着这不是最简单的插件。在您的情况下,我们的想法是从moduleSets 生成dir 分布,您必须为此创建一个自定义assembly descriptor

    我建议从 Maven 书籍的章节 8.2. Assembly Basics 开始,并特别注意章节 8.5.5. moduleSets Sections

    【讨论】:

      【解决方案2】:

      在阅读了其他答案的链接后,我现在要尝试以下内容:

              <plugin>
                  <artifactId>maven-resources-plugin</artifactId>
      
                  <executions>
                      <execution>
                          <id>copy-jars</id>
                          <phase>package</phase>
                          <goals>
                              <goal>copy-resources</goal>
                          </goals>
                          <configuration>
                              <resources>
                                  <resource>
                                      <directory>../src/my-module/target</directory>
                                      <includes>
                                          <include>**/my-module*.jar</include>
                                      </includes>
                                  </resource>
                              </resources>
                          </configuration>
                      </execution>
                  </executions>
              </plugin>
      

      不完全漂亮,但在研究 Assembly 插件以寻找可能的长期解决方案时,这将是可行的。

      【讨论】:

        【解决方案3】:

        我猜maven组装插件可以做到这一点

        【讨论】:

          【解决方案4】:

          正如@Pangea 所说的汇编插件会做到这一点。只需运行assembly:assembly 目标并适当设置outputDirectory 参数。

          更多信息http://maven.apache.org/plugins/maven-assembly-plugin/assembly-mojo.html

          【讨论】:

          • “仅仅”运行assembly:assembly 是不够的。
          猜你喜欢
          • 2014-04-16
          • 2019-02-15
          • 2011-07-19
          • 2011-02-18
          • 2017-04-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多