tags:

views:

87

answers:

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"&gt;
<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!

A: 

I figured this out. I needed to include <dependencySet> element inside my <moduleSet> like so:

<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"&gt;
    <id>Install-Package</id>
    <formats>
        <format>dir</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <moduleSets>
        <moduleSet>
            <binaries>
                <unpack>false</unpack>
                <dependencySets>
                    <dependencySet>
                        <unpack>false</unpack>
                        <scope>compile</scope>
                        <outputDirectory>dependencies</outputDirectory>
                    </dependencySet>
                </dependencySets>
            </binaries>
        </moduleSet>
    </moduleSets>
</assembly>
Greg
+1  A: 

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"&gt;
  <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>
Pascal Thivent
Got it working. Thanks again for your help!
Greg
@Greg You're welcome. Good you decided to go the maven assembly way, that's the best choice for your scenario.
Pascal Thivent