2

I am building a multimodule project with Maven where one module represents the shaded version of the other module:

parent
|- base
|- base-shaded

The base module contains all my source files but with dependencies I want to import into my own namespace. This shaded module is described by my base-shaded module which basically only contains a POM which configures a dependency on base and the Maven Shade plugin.

This works fine. The Shade plugin includes all the dependencies and creates a shaded artifact, including a source artifact. However, I am missing a javadoc artifact which is not created by the Shade plugin. Therefore, I attempted to copy the base module's javadoc artifact. However, the release:release goal ignores these artifacts which prevents me to deploying to Maven Central. Still, I managed to include copy these files and include them in install target.

Is there a canonical way of including a non-assembled file in a build? I start to think that I might be the wrong approach.

Here is the plugin configuration of my base-shaded POM. Sorry that it is so much, but in the end, it is Maven XML:

    <!-- Shade dependencies -->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>${version.plugin.shade}</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
        <configuration>
        <shadedArtifactAttached>false</shadedArtifactAttached>
        <createDependencyReducedPom>true</createDependencyReducedPom>
        <dependencyReducedPomLocation>
          ${project.build.directory}/dependency-reduced-pom.xml
        </dependencyReducedPomLocation>
        <createSourcesJar>true</createSourcesJar>
        <shadeSourcesContent>true</shadeSourcesContent>
        <relocations>
          <relocation>
            <pattern>${shade.source}</pattern>
            <shadedPattern>${shade.target}</shadedPattern>
          </relocation>
        </relocations>
      </configuration>
    </execution>
  </executions>
</plugin>
<!-- Copy dependency version's javadoc artifacts -->
<plugin>
  <groupId>com.github.goldin</groupId>
  <artifactId>copy-maven-plugin</artifactId>
  <version>${version.plugin.copy}</version>
  <executions>
    <execution>
      <phase>package</phase>
        <goals>
          <goal>copy</goal>
        </goals>
        <configuration>
          <resources>
            <resource>
              <targetPath>${project.build.directory}</targetPath>
              <file>
                ${project.basedir}/../base/target/base-${project.version}-javadoc.jar
              </file>
              <destFileName>base-${project.version}-javadoc.jar</destFileName>
            </resource>
          <resource>
            <targetPath>${project.build.directory}</targetPath>
            <file>
              ${project.basedir}/../base/target/base-${project.version}-javadoc.jar.asc
            </file>
            <destFileName>base-shaded-${project.version}-javadoc.jar.asc</destFileName>
          </resource>
        </resources>
      </configuration>
    </execution>
  </executions>
</plugin>
<!-- Because the javadoc files are copied manually, they must be installed manually as well -->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-install-plugin</artifactId>
  <executions>
    <execution>
      <id>install-javadoc</id>
      <phase>install</phase>
      <goals>
        <goal>install-file</goal>
      </goals>
      <configuration>
        <groupId>${project.groupId}</groupId>
        <artifactId>${project.artifactId}</artifactId>
        <version>${project.version}</version>
        <packaging>jar</packaging>
        <classifier>javadoc</classifier>
        <file>${build.directory}/base-shaded-${project.version}-javadoc.jar</file>
      </configuration>
    </execution>
    <execution>
      <id>install-javadoc-asc</id>
      <phase>install</phase>
      <goals>
        <goal>install-file</goal>
      </goals>
      <configuration>
        <groupId>${project.groupId}</groupId>
        <artifactId>${project.artifactId}</artifactId>
        <version>${project.version}</version>
        <packaging>jar.asc</packaging>
        <classifier>javadoc</classifier>
        <file>${build.directory}/base-shaded-${project.version}-javadoc.jar.asc</file>
      </configuration>
    </execution>
  </executions>
</plugin>
Tunaki
  • 132,869
  • 46
  • 340
  • 423
Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192

2 Answers2

0

Of course, there is a plugin for this task, the build-helper-maven-plugin.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
  • 2
    This would have been a lot more helpful with an example implementing your request instead of a simple link. :(. https://xkcd.com/979/ is relevant – Daniel Widdis Jun 25 '20 at 15:09
0

We use something like the following to attach the javadoc produced by the unshaded module into the shaded module

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>attach</id>
            <phase>package</phase>
            <goals>
                <goal>attach-artifact</goal>
            </goals>
            <configuration>
               <artifacts>
                  <artifact>
                      <file>../unshaded-module/target/unshaded-module-${project.version}-javadoc.jar</file>
                      <type>jar</type>
                      <classifier>javadoc</classifier>
                  </artifact>
               </artifacts>
            </configuration>
        </execution>
    </executions>
 </plugin>
Tristan Tarrant
  • 1,299
  • 6
  • 6