Search code examples
javadocmaven-central

How to upload an artifact to Maven Central with an empty javadoc jar (or empty sources jar), because of no Java code nor resources?


I have this small module, which contains only some property file. The property file resides in the root of the project and needs to stay there. Nothing more. When uploading to Maven central via sonatype, a javadoc jar is mandatory so I had to create one.

So I don't have src/main/java or src/main/resources. How do I do it?

The javadoc plugin doesn't provide any options for this.

For the sources jar, just the same. Sonatype requires at least the presence of a sources jar, even if it is empty...

To date (december 2018) I could not find a working solution on the internet.


Solution

  • I've found this very simple trick! No extra plugins needed, just extend the current maven-jar-plugin with two extra executions, one for the javadoc and one for the sources:

            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>default-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>javadoc-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <classifier>javadoc</classifier>
                        </configuration>
                    </execution>
                    <execution>
                        <id>sources-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <classifier>sources</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    

    When executing 'deploy' it will generate an extra empty javadoc and sources jar.