maven-assembly plugin – how to create nested assemblies

With your existing configuration, your two separate configurations for the assembly plugin will be merged, and the configurations will also be merged.

To achieve your goal you should define a single assembly-plugin configuration with multiple nested executions, then define the configuration for each execution inside it. The assembly plugin will then execute each assembly sequentially, so the jar-with-dependencies jar will be available for inclusion in the dist jar. Also note the attached goal is deprecated in favour of the single goal.

Also note that paths in the assembly are relative to the root, and to include a particular file you should use the <files> element rather than the <filesets> element. You can also specify properties in the assembly to make it less fragile to change.

The rearranged configuration and assembly below should do what you’re after:

Assembly descriptor:

<assembly>
  <id>dist</id>
  <formats>
    <format>tar.gz</format>
    <format>tar.bz2</format>
    <format>zip</format>
  </formats>
  <files>
    <file>
      <source>
        target/${project.artifactId}-${project.version}-jar-with-dependencies.jar
      </source>
      <outputDirectory>/</outputDirectory>
    </file>
  </files>
  <fileSets>
    <fileSet>
      <directory>${project.basedir}/src/main/resources</directory>
      <includes>
        <include>*</include>
      </includes>
     <outputDirectory>/</outputDirectory> 
    </fileSet>
  </fileSets>
</assembly>

Assembly plugin:

<plugin>
 <artifactId>maven-assembly-plugin</artifactId>
 <executions>
  <execution>
   <id>jar-with-dependencies</id>
   <phase>package</phase>
   <goals>
    <goal>single</goal>
   </goals>
   <configuration>
    <descriptorRefs>
     <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
    <archive>
     <manifest>
      <mainClass>quicksearch.QuickSearchApp</mainClass>
     </manifest>
    </archive>
   </configuration>
  </execution>
  <execution>
   <id>dist</id>
   <phase>package</phase>
   <goals>
    <goal>single</goal>
   </goals>
   <configuration>
    <descriptors>
     <descriptor>src/main/assembly/dist.xml</descriptor>
    </descriptors>
   </configuration>
  </execution>
 </executions>
</plugin>

Leave a Comment