Maven Assembly Plugin – Include Dependencies from Sub-Modules

maven-2

I am trying to setup the assembly plugin for a large multi-module project. The goal right now is to just get all of my artifacts into a directory. Here is my descriptor:

    <assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>Install-Package</id>
<formats>
    <format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
    <dependencySet>
        <unpack>false</unpack>
        <scope>runtime</scope>
        <outputDirectory>dependencies</outputDirectory>
    </dependencySet>
</dependencySets>
<moduleSets>
    <moduleSet>
        <binaries>
            <unpack>false</unpack>
        </binaries>
    </moduleSet>
</moduleSets>

Currently, this copies all of my artifacts to the assembly directory. So far, so good. The problem is that the dependencies folder only includes dependencies that are listed in the main pom file. Is there a way to include the dependencies of the sub modules in the assembly without listing them all in the root pom? (Including them all on the root pom would add extra unused dependencies to the sub modules if they are built separately).

Thanks!

Best Answer

The problem is that the dependencies folder only includes dependencies that are listed in the main pom file.

Yes, this is what a "top" dependencySets does.

Is there a way to include the dependencies of the sub modules in the assembly without listing them all in the root pom?

Remove the "top" dependencySets and declare one under the binaries element of your moduleSet:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
  <id>Install-Package</id>
  <formats>
    <format>dir</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <binaries>
        <unpack>false</unpack>
        <dependencySets>
          <dependencySet>
            <unpack>false</unpack>
            <scope>runtime</scope>
            <outputDirectory>dependencies</outputDirectory>
          </dependencySet>
        </dependencySets>
      </binaries>
    </moduleSet>
  </moduleSets>
</assembly>