uploadmaven-pluginnexusstagingmaven-central

Maven Central skip uploading a submodule


In Maven multi module project,

   Parent
         Module A
         Module B

I want to upload Parent and Module A artifacts to Maven Central but not the Module B artifact.

I am using nexus-staging-maven-plugin. I added skip parameter in Module B both for maven-deploy-plugin and nexus-staging-maven-plugin, but still build is uploading Module B to maven central.

Is there any way to skip Module B from getting uploaded.


Solution

  • After much effort, I figured it out myself the way to block the release of certain modules to Maven Central (OSSRH). The maven-deploy-plugin uploads/deploys the artifacts to OSSRH and then the nexus-staging-maven-plugin stages and releases it. The trick is to add nexus plugin only to the modules which we want to release. I added following to parent and moduleA pom but not to the moduleB pom.

    <build>
        <plugins>
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>${nexus-staging-maven-plugin.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
                </configuration>
            </plugin>
            ...
    

    With this setup, the deploy-plugin uploads parent, moduleA and moduleB artifacts, but nexus-staging-maven-plugin stages and releases only parent and moduleA. Since there is no nexus plugin config in moduleB pom.xml, its artifact is not released to OSSRH.

    However, without nexus-staging plugin in moduleB pom.xml you will get "missing nexusUrl" error if you run goals of nexus-staging such as mvn nexus-staging:release, mvn nexus-staging:drop or mvn nexus-staging:rc-list etc., In case you want to run goals of nexus-staging then temporarily add nexus-staging plugin snippet to moduleB; run these commands and remove the plugin from moduleB once work is done.

    We can also use this workaround to upload single module. For example, I mistakenly uploaded moduleA-1.0 without the parent-1.0 artifact. When I again tried to upload both parent-1.0 and moduleA-1.0 artifacts it failed, as OSSRH doesn't allow overwrite of artifacts. The release was broken as parent was missing. To upload just the parent-1.0, I kept nexus-staging plugin in parent, removed it from moduleA and was able to upload just parent-1.0.