title: Maven include JavaDoc Jar in Assembly
body: <p>I have a project with multiple modules, including on that is responsible for building the final assembly from the artifacts of the other modules.  As part of the assembly, I want to include the JavaDocs for two of the other modules.  I have updated the pom files for those modules to generate the JavaDoc JAR files, and modified the assembly project to list those JavaDoc Jar files as dependencies.  However, when I build the project from the top level, the assembly project tells me that it cannot find the javaDoc jars.  If I install all the other modules first, then build the assembly module directly, the assembly will build fine.</p>
  
  <p>How can I get the assembly to build correctly, with all the specified dependencies, when run from the top level project?</p>
  
  <p><b><i>Edited to add more info at the request of the responders:</i></b></p>
  
  <p>Here's a simplified project I threw together to demonstrate the issue. The directory layout is as follows: </p>
  
  <pre>
  sample/
    \--pom.xml
    \--module1/
         \--pom.xml
         \--src/ 
              \--{the usual main/java layout with a single java file, with javadocs}
    \--package/
         \--pom.xml
         \--assemblies/
              \--bin.xml
  </pre>
  
  <p>The top level pom.xml, under sample, looks like this:</p>
  
  <pre>
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
    &lt;groupId&gt;test&lt;/groupId&gt;
    &lt;artifactId&gt;project&lt;/artifactId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;pom&lt;/packaging&gt;
  
    &lt;modules&gt;
      &lt;module&gt;module1&lt;/module&gt;
      &lt;module&gt;package&lt;/module&gt;
    &lt;/modules&gt;
  
    &lt;build&gt;
      &lt;defaultGoal&gt;package&lt;/defaultGoal&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </pre>
  
  <p>The module1 pom.xml is a basic project file with an entry for the javadoc plugin:</p>
  
  <pre>
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
    &lt;groupId&gt;test&lt;/groupId&gt;
    &lt;artifactId&gt;module1&lt;/artifactId&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
    &lt;build&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-javadoc-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.6&lt;/version&gt;
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;javadoc-jar&lt;/id&gt;
              &lt;phase&gt;package&lt;/phase&gt;
              &lt;goals&gt;
                &lt;goal&gt;jar&lt;/goal&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  
  </pre>
  
  <p>The package module pom file specifies dependencies on the module1 Jar file and the module1 JavaDoc jar file:</p>
  
  <pre>
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
    &lt;!-- The Basics --&gt;
    &lt;groupId&gt;test&lt;/groupId&gt;
    &lt;artifactId&gt;packaging&lt;/artifactId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;pom&lt;/packaging&gt;
  
    &lt;!-- Shared Dependencies --&gt;
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;test&lt;/groupId&gt;
        &lt;artifactId&gt;module1&lt;/artifactId&gt;
        &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
        &lt;groupId&gt;test&lt;/groupId&gt;
        &lt;artifactId&gt;module1&lt;/artifactId&gt;
        &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
        &lt;classifier&gt;javadoc&lt;/classifier&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  
    &lt;!-- Build Settings --&gt;
    &lt;build&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.2-beta-4&lt;/version&gt;
          &lt;configuration&gt;
            &lt;descriptors&gt;
              &lt;descriptor&gt;assemblies/bin.xml&lt;/descriptor&gt;
            &lt;/descriptors&gt;
          &lt;/configuration&gt;
  
          &lt;executions&gt;
            &lt;execution&gt;
              &lt;id&gt;make-assembly&lt;/id&gt; &lt;!-- this is used for inheritance merges --&gt;
              &lt;phase&gt;package&lt;/phase&gt; &lt;!-- append to the packaging phase. --&gt;
              &lt;goals&gt;
                &lt;goal&gt;single&lt;/goal&gt; &lt;!-- goals == mojos --&gt;
              &lt;/goals&gt;
            &lt;/execution&gt;
          &lt;/executions&gt;
  
        &lt;/plugin&gt;
  
      &lt;/plugins&gt;
    &lt;/build&gt;
  
  &lt;/project&gt;
  </pre>
  
  <p>And finally, the assembly file includes the two dependencies, with the JavaDoc jar file being stored unpacked into the assembled file.  I have each dependencySet use strict Filtering to highlight the inability of the assembly plugin to find the specified files.</p>
  
  <pre>
  &lt;assembly&gt;
    &lt;id&gt;bin&lt;/id&gt;
    &lt;formats&gt;
      &lt;format&gt;jar&lt;/format&gt;
    &lt;/formats&gt;
    &lt;includeBaseDirectory&gt;false&lt;/includeBaseDirectory&gt;
  
    &lt;dependencySets&gt;
      &lt;dependencySet&gt;
        &lt;excludes&gt;
          &lt;!-- Exclude the Jars that are included in later sections --&gt;
          &lt;exclude&gt;test:module1:jar:javadoc&lt;/exclude&gt;
        &lt;/excludes&gt;
        &lt;outputDirectory&gt;lib&lt;/outputDirectory&gt;
        &lt;unpack&gt;false&lt;/unpack&gt;
        &lt;useTransitiveDependencies&gt;true&lt;/useTransitiveDependencies&gt;
        &lt;useTransitiveFiltering&gt;false&lt;/useTransitiveFiltering&gt;
        &lt;useProjectArtifact&gt;false&lt;/useProjectArtifact&gt;
      &lt;/dependencySet&gt;
  
      &lt;dependencySet&gt;
        &lt;includes&gt;
          &lt;include&gt;test:module1:jar:javadoc&lt;/include&gt;
        &lt;/includes&gt;
        &lt;outputDirectory&gt;docs&lt;/outputDirectory&gt;
        &lt;unpack&gt;true&lt;/unpack&gt;
        &lt;useTransitiveDependencies&gt;true&lt;/useTransitiveDependencies&gt;
        &lt;useProjectArtifact&gt;false&lt;/useProjectArtifact&gt;
        &lt;useStrictFiltering&gt;true&lt;/useStrictFiltering&gt;
      &lt;/dependencySet&gt;
    &lt;/dependencySets&gt;
  &lt;/assembly&gt;
  </pre>
  
  <p>Running this project from the top results in the following output:</p>
  
  <pre>
  [INFO] Scanning for projects...
  [INFO] Reactor build order: 
  [INFO]   Unnamed - test:module1:jar:1.0-SNAPSHOT
  [INFO]   Unnamed - test:packaging:pom:1.0-SNAPSHOT
  [INFO]   Unnamed - test:project:pom:1.0-SNAPSHOT
  [INFO] ------------------------------------------------------------------------
  [INFO] Building Unnamed - test:module1:jar:1.0-SNAPSHOT
  [INFO]    task-segment: [clean, package]
  [INFO] ------------------------------------------------------------------------
  [INFO] [clean:clean]
  [INFO] Deleting directory /Users/john/Documents/src/workspace/sample/module1/target
  [INFO] [resources:resources]
  [WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
  [INFO] Copying 0 resource
  [INFO] [compiler:compile]
  [INFO] Compiling 1 source file to /Users/john/Documents/src/workspace/sample/module1/target/classes
  [INFO] [resources:testResources]
  [WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
  [INFO] skip non existing resourceDirectory /Users/john/Documents/src/workspace/sample/module1/src/test/resources
  [INFO] [compiler:testCompile]
  [INFO] No sources to compile
  [INFO] [surefire:test]
  [INFO] No tests to run.
  [INFO] [jar:jar]
  [INFO] Building jar: /Users/john/Documents/src/workspace/sample/module1/target/module1-1.0-SNAPSHOT.jar
  [INFO] [javadoc:jar {execution: javadoc-jar}]
  [WARNING] Source files encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
  Loading source files for package test...
  Constructing Javadoc information...
  Standard Doclet version 1.5.0_20
  Building tree for all the packages and classes...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/test//AClass.html...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/test//package-frame.html...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/test//package-summary.html...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/test//package-tree.html...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/constant-values.html...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/test/class-use//AClass.html...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/test//package-use.html...
  Building index for all the packages and classes...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/overview-tree.html...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/index-all.html...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/deprecated-list.html...
  Building index for all classes...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/allclasses-frame.html...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/allclasses-noframe.html...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/index.html...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/help-doc.html...
  Generating /Users/john/Documents/src/workspace/sample/module1/target/apidocs/stylesheet.css...
  [INFO] Building jar: /Users/john/Documents/src/workspace/sample/module1/target/module1-1.0-SNAPSHOT-javadoc.jar
  [INFO] ------------------------------------------------------------------------
  [INFO] Building Unnamed - test:packaging:pom:1.0-SNAPSHOT
  [INFO]    task-segment: [clean, package]
  [INFO] ------------------------------------------------------------------------
  [INFO] [clean:clean]
  [INFO] Deleting directory /Users/john/Documents/src/workspace/sample/package/target
  [INFO] [site:attach-descriptor]
  [INFO] [assembly:single {execution: make-assembly}]
  [INFO] Reading assembly descriptor: assemblies/bin.xml
  [WARNING] The following patterns were never triggered in this artifact exclusion filter:
  o  'test:module1:jar:javadoc'
  
  [WARNING] The following patterns were never triggered in this artifact inclusion filter:
  o  'test:module1:jar:javadoc'
  
  [INFO] ------------------------------------------------------------------------
  [ERROR] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] : org.apache.maven.plugin.assembly.model.Assembly@139c27
  Assembly is incorrectly configured: bin
  
  Assembly: bin is not configured correctly: One or more filters had unmatched criteria. Check debug log for more information.
  [INFO] ------------------------------------------------------------------------
  [INFO] For more information, run Maven with the -e switch
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 12 seconds
  [INFO] Finished at: Wed Oct 07 15:23:26 PDT 2009
  [INFO] Final Memory: 26M/52M
  [INFO] ------------------------------------------------------------------------
  </pre>
  
  <p>I have posted this project for <a href="http://files.me.com/jchaager/cwi8js" rel="noreferrer">download</a>.</p>