I have a Maven multi module project of which some of the sub modules are only for internal use. I don't wish to publish any visible Javadoc for it, as it should not be used directly by 3rd parties. There is not a single public package in them (the package name itself has something like a.b.c.internal.d).
However, to release a jar to Maven Central, OSS Sonatype requires that all library jars have accompanying sources and javadoc jars.
How can I force a javadoc jar to be created with a fixed index or so that tells the purpose of the sub module? A package-info.java comes to mind, but I have no public packages (all packages with the word "internal" in it are ignored).
Don't use the Javadoc tool to produce a jar with non-standard content: use maven-jar-plugin instead to manually create one.
Initial solution taken from https://vzurczak.wordpress.com/2014/08/01/generate-an-empty-javadoc-jar-file/
Here's the final solution I settled on and works generically for all submodules when configured in the parent pom:
Define two profiles:
Maven config:
<profiles>
<profile>
<id>standard-javadoc</id>
<activation>
<file><missing>src/main/javadoc</missing></file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<show>public</show>
<failOnError>false</failOnError>
<detectOfflineLinks>false</detectOfflineLinks>
<doclint>all,-missing</doclint>
<nohelp>true</nohelp>
<excludePackageNames>*.internal.*,testutil,demo</excludePackageNames>
<quiet>true</quiet>
</configuration>
</execution>
</executions>
<configuration>
<failOnError>false</failOnError>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>custom-javadoc</id>
<activation>
<file><exists>src/main/javadoc</exists></file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>javadoc</classifier>
<classesDirectory>${project.basedir}/src/main/javadoc</classesDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>