0

I would like to enable my Maven build to fetch all source and JavaDoc jars and to unpack all JavaDoc jars only once in a multi-module Maven project.

I managed with the help of the Maven dependency plugin to to fetch all source and JavaDoc jars for every sub-module. But I need them only once to be unpacked and not for every sub-module.

The best solution would be to be able to unpack all managed dependencies specified in the project parent POM. Any idea how to achieve this?

Here is my current solution:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <id>fetch-source</id>
      <goals>
        <goal>sources</goal>
      </goals>
    </execution>
    <execution>
      <id>fetch-doc</id>
      <goals>
        <goal>resolve</goal>
      </goals>
      <configuration>
        <classifier>javadoc</classifier>
      </configuration>
    </execution>
    <execution>
      <id>unpack-javadoc</id>
      <goals>
        <goal>unpack-dependencies</goal>
      </goals>
      <configuration>
        <classifier>javadoc</classifier>
          <useSubDirectoryPerArtifact>true</useSubDirectoryPerArtifact>
        <stripClassifier>true</stripClassifier>
      </configuration>
    </execution>
  </executions>
</plugin>
Oliver
  • 3,815
  • 8
  • 35
  • 63

2 Answers2

0

It sounds like you want to make use of the <inherited/> element/property for plugin executions. For example:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <id>fetch-source</id>
      <!-- Will prevent this plugin execution in child modules. -->
      <inherited>false</inherited>
      <goals>
        <goal>sources</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Karl M. Davis
  • 606
  • 1
  • 7
  • 22
  • `false` prevents only the recursive execution of this goal. Since I have a multi-module project the packaging type of my parent POM is set to `pom`. Hence it has no dependencies itself. – Oliver Sep 17 '13 at 08:50
0

Ok, I ended up with this profile:

<profile>
  <id>fetchdocandsource</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>fetch-source</id>
            <goals>
              <goal>sources</goal>
            </goals>
          </execution>
          <execution>
            <id>fetch-doc</id>
            <goals>
              <goal>resolve</goal>
            </goals>
            <configuration>
              <classifier>javadoc</classifier>
            </configuration>
          </execution>
          <execution>
            <id>unpack-javadoc</id>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <classifier>javadoc</classifier>
              <useRepositoryLayout>true</useRepositoryLayout>
              <outputDirectory>${env.HOME}/javadoc</outputDirectory>
              <stripClassifier>true</stripClassifier>
              <markersDirectory>${env.HOME}/javadoc/.markers</markersDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>

In the current configuration I am able to fetch all source and JavaDoc jars and to store all JavaDoc files in a central directory. Having a central directory for the marker files (see <markersDirectory/>) prevents the depenency plugin from unpacking the same JavaDoc dependency more than once for the same or for different projects.

Oliver
  • 3,815
  • 8
  • 35
  • 63