Using both aggregate and jar goals for javadoc

692 views Asked by At

I would like to generate javadoc for my whole project using the aggregate goal but I would also like to generate javadoc jars for several sub-projects. In my parent pom.xml I added the following pluginManagement to allow sub-projects to generate javadoc jars easily:

<project>
  ...
  <build>
    <pluginManagement>
      <plugin>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.9</version>
        <executions>
          <execution>
            <goals>
              <goal>jar</goal>
            </goals>
            ...

Then in the sub-projects that need a javadoc jar I added:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <plugin>
          <artifactId>maven-javadoc-plugin</artifactId>
        </plugin>
        ...

So far so good. Now I wanted to use the aggregate goal to get a full set of javadoc so I added another reference to the javadoc plugin to the parent pom:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-javadoc-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>aggregate</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...

This causes the javadoc plugin to get pulled into every sub-project instead of just the few that need it. It seems that jar and aggregate goals work well independently but when used together they cause issues. Anyone solved something like this?

Thanks in advance!

1

There are 1 answers

0
myshkin5 On BEST ANSWER

I figured it out by doing something similar to this: Can I configure multiple plugin executions in pluginManagement, and choose from them in my child POM? Basically I added an id to both executions and a phase of none to the javadoc jar instance. Then I overrode the phase back to package in only the sub-projects that needed a javadoc jar. Here is the pluginManagement in the parent pom:

<project>
  ...
  <build>
    <pluginManagement>
      <plugin>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.9.1</version>
          <executions>
            <execution>
              <id>javadoc-jar</id>
              <phase>none</phase>
              <goals>
                <goal>jar</goal>
              </goals>
              ...

Then in the sub-project pom where needed the following turns on the javadoc jar:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-javadoc-plugin</artifactId>
        <executions>
          <execution>
            <id>javadoc-jar</id>
            <phase>package</phase>
          </execution>
        </executions>
      </plugin>
      ...