7

我有以下形式的项目

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

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

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

我怎样才能告诉 maven 只直接组装 tar.gzprojectAssembly而不浪费时间打包和解包中间档案?

4

1 回答 1

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>

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

于 2013-05-14T06:19:10.070 回答