加速多个模块的maven组装

时间:2013-04-09 05:54:13

标签: maven maven-assembly-plugin

我正在使用以下形式的项目

- pom.xml
- projectA
  - pom.xml
  - src/main/
    - java
    - startupScript
- projectB
  - pom.xml
  - src/main/
    - java
    - startupScript
- projectAssembly
  - pom.xml

我希望projectAssembly生成一个tar.gz,其中包含两个文件夹,一个用于projectA,一个用于projectB,在每个文件夹中,都有项目的依赖项和startupScript库。

“天真”的方法是将assembly.xml文件添加到每个项目中,文件大致如下:

<assembly>
<formats>
    <format>tar.gz</format>
</formats>
<baseDirectory>/${project.artifactId}</baseDirectory>
<fileSets>
    <fileSet>
        <directory>${basedir}/src/main/startupScripts</directory>
        <outputDirectory>/startupScripts</outputDirectory>
    </fileSet>
 </fileSets>
<dependencySets>
    <dependencySet>
        <outputDirectory>/lib</outputDirectory>
    </dependencySet>
</dependencySets>
</assembly>

然后,在projectAssembly中,依赖于<type>tar.gz</type>projectA的{​​{1}},并添加一个大致类似

的汇编文件
projectB

但是,这不起作用,我不需要项目<assembly> <dependencySets> <dependencySet> <outputDirectory>/</outputDirectory> <unpack>true</unpack> </dependencySet> </dependencySets> </assembly> tar.gz的中间A,并且生成它们,特别是如果它们有很多依赖项,需要很长时间

如何告诉maven直接汇编B的tar.gz而不浪费时间打包和拆包中间档案?

1 个答案:

答案 0 :(得分:1)

projectAssembly中的程序集描述符需要看起来像这样(参见里面的注释):

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bin</id>
<formats>
  <format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
  <moduleSet>

    <!-- Enable access to all projects in the current multimodule build! -->
    <useAllReactorProjects>true</useAllReactorProjects>

    <!-- Now, select which projects to include in this module-set. -->
    <includes>
      <include>*:projectA</include>
      <include>*:projectB</include>
    </includes>

    <!-- Select and map resources from each module -->
    <sources>
      <includeModuleDirectory>false</includeModuleDirectory>
      <fileSets>
        <fileSet>
          <directory>src/main/startupScript</directory>
          <outputDirectory>${module.artifactId}/startupScript</outputDirectory>
        </fileSet>
      </fileSets>
    </sources>

   <!-- Select and map dependencies from each module -->
    <binaries>
      <dependencySets>
        <dependencySet>
          <outputDirectory>${module.artifactId}/lib</outputDirectory>
        </dependencySet>
      </dependencySets>
    </binaries>
  </moduleSet>
</moduleSets>
</assembly>

我相信这就是你所需要的。如果没有,请告诉我们..