【问题标题】:Speeding up maven assembly of multiple modules加速多个模块的 Maven 组装
【发布时间】:2013-04-09 05:54:13
【问题描述】:

我有一个如下形式的项目

- 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中,依赖projectAprojectB&lt;type&gt;tar.gz&lt;/type&gt;,并添加一个大致如下的汇编文件

<assembly>
<dependencySets>
    <dependencySet>
        <outputDirectory>/</outputDirectory>
        <unpack>true</unpack>
    </dependencySet>
</dependencySets>
</assembly>

这可行,但是,我不需要项目 AB 的中间 tar.gz,并且生成它们,特别是如果它们有很多依赖项,需要很长时间。

如何告诉 maven 只直接组装 projectAssembly 的 tar.gz 而不会浪费时间打包和解压中间档案?

【问题讨论】:

  • 你需要项目a和b的tar.gz文件中的依赖吗?如果不只是从程序集描述符中删除dependencySets。
  • @khmarbaise 但它们将如何出现在assemblyProject 创建的最终 tar.gz 中?
  • 您好!您使用的是哪个 Maven 版本?
  • @Jan 嗨,3.0.1。好像没什么大不了的。
  • 对我来说确实如此:我认为 moduleSets 可以帮助你,但我会在给出答案之前尝试一下 - 唉,我只使用 Maven 2。

标签: maven maven-assembly-plugin


【解决方案1】:

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

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

我相信这就是您所需要的。如果不让我们知道..

【讨论】:

    猜你喜欢
    • 2011-05-02
    • 1970-01-01
    • 2011-02-11
    • 2021-01-04
    • 2012-03-06
    • 2014-06-12
    • 1970-01-01
    • 2011-04-11
    • 2018-08-15
    相关资源
    最近更新 更多