The maven assembly plugin moduleset sources instructions are not including any files and not matching the included modules

marathon picture marathon · Jun 26, 2013 · Viewed 21.5k times · Source

I have a multi-module maven project, and I'm trying to get the moduleset sources portion of the assembly plugin to work.

I have modules "module_parent", "module_a", and "module_assembly".

module_a and module_assembly are children of module_parent.

module_assembly has a declared pom dependency on module_a.

module_assmebly has the assembly plugin, with the assembly.xml looking like:

<?xml version="1.0"?>
<assembly>
  <id>bin</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <useAllReactorProjects>true</useAllReactorProjects>
      <includes>
        <include>com.mystuff:module_a</include>
      </includes>
      <sources>
        <fileSets>
          <fileSet>
            <outputDirectory>/</outputDirectory>
            <excludes>
              <exclude>**/target/**</exclude>
            </excludes>
            <directory>/</directory>
          </fileSet>
        </fileSets>
      </sources>
    </moduleSet>
  </moduleSets>
</assembly> <!-- -->

I have an explicit dependency in module_assembly for module_a. The dependency in module_assembly's pom looks like:

<dependencies>
    <dependency>
        <groupId>com.mystuff</groupId>
        <artifactId>module_a</artifactId>
        <version>1.0</version>
        <type>pom</type>
    </dependency>
</dependencies>

The error I get from mvn package with debug turned on is:

[DEBUG] All known ContainerDescritporHandler components: [metaInf-services, plexus, metaInf-spring, file-aggregator]
[DEBUG] No dependency sets specified.
[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  'com.mystuff:module_a'

[DEBUG] Cannot find ArtifactResolver with hint: project-cache-aware
org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
      role: org.apache.maven.artifact.resolver.ArtifactResolver
  roleHint: project-cache-aware
        at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:257)
        at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:233)
        at
  <snip>
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.util.NoSuchElementException
        at java.util.Collections$EmptyIterator.next(Collections.java:3006)
        at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:253)
        ... 43 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
<snip>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2:single (make-assembly) on project apm-server-distribution: Failed to create assembly: Error creating assembly archive bin: You must set at least one file. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2:single (make-assembly) on project apm-server-distribution: Failed to create assembly: Error creating assembly archive bin: You must set at least one file.

I think the main problem is this warning line:

[WARNING] The following patterns were never triggered in this artifact inclusion filter:
    o  'com.mystuff:module_a'

How do I correct this?

Answer

John Ament picture John Ament · Jul 6, 2013

If module_assembly doesn't have a child reference to your module, it's not counted as a module. Note the content here refers to children only: http://maven.apache.org/plugins/maven-assembly-plugin/advanced-module-set-topics.html

If you want to do this, you need to use a dependencySet rather than a moduleSet.

PS - Thank you for the bounty!