Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speeding up maven assembly of multiple modules

I'm having a project of the following form

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

I want projectAssembly to produce a tar.gz that would contain two folders one for projectA and one for projectB, in each folder, there would be project's dependencies and the startupScript library.

The "naive" way to do that is to add assembly.xml file to each project, a file which roughly looks like:

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

Then, in the projectAssembly, depend on <type>tar.gz</type> of both projectA and projectB, and add an assembly file which roughly looks like

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

This works, however, I do not need the intermediate tar.gz of projects A and B, and producing them, especially if they have a lot of dependencies, takes a long time.

How can I tell maven to directly assembly only the tar.gz of projectAssembly without wasting times on packing and unpacking intermediate archives?

like image 794
mikebloch Avatar asked Apr 09 '13 05:04

mikebloch


1 Answers

Your assembly descriptor in the projectAssembly needs to look something like this (See comments inside):

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

I believe that would be what you need. If not let us know..

like image 192
Niels Bech Nielsen Avatar answered Oct 05 '22 03:10

Niels Bech Nielsen