代码之家  ›  专栏  ›  技术社区  ›  MattGWagner

Maven pom.xml-项目聚合

  •  4
  • MattGWagner  · 技术社区  · 14 年前

    我们有一个aggregation.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”中各个模块的输出目录,因为它们也可以单独构建。

    我是一个专业的新人,所以我肯定有一个简单的方法来做这件事我错过了。

    4 回复  |  直到 14 年前
        1
  •  2
  •   Pascal Thivent    14 年前

    在构建之后,有没有一种方法可以将构建(.JAR文件)中的工件从这两个模块中获取到一个公共的'dist'目录中?

    Maven Assembly Plugin 可以做到这一点,它是非常强大和灵活的。但是强大和灵活也意味着这不是最容易使用的插件。在你的例子中,这个想法是产生一个 dir moduleSets 你必须创建一个自定义 assembly descriptor 为了这个。

    我建议从第一章开始 8.2. Assembly Basics 8.5.5. moduleSets Sections .

        2
  •  1
  •   MattGWagner    14 年前

    在阅读了其他答案的链接之后,下面是我现在要尝试的:

            <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>
    

    不是很漂亮,但是在研究汇编插件寻找一个可能的长期解决方案时,这就可以了。

        3
  •  0
  •   Aravind Yarram    14 年前

    我猜maven汇编插件可以做到这一点

        4
  •  0
  •   Eugene Ryzhikov    14 年前

    正如@Pangea所说的组装插件可以做到这一点。快跑 assembly:assembly 适当设定的目标 outputDirectory

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