17

I'm looking into replacing the maven-deploy-plugin with the nexus-staging-maven-plugin.

Now some of the sub-modules of my project (e.g. integration test modules) are not to be deployed to the Nexus server. I used to disable the deployment of these modules via the "maven.deploy.skip" property. I cannot find anything comparable for the nexus-staging-maven-plugin, though. Is there another way for skipping single modules from deployment using this plug-in?

I also tried to bind the plug-in to the pseudo phase "none" as described here, but examining the effective POM, there is still the injected execution of the plug-in (I assume that's due to the way how it replaces the existing deploy plug-in).

Oliver Gondža
  • 3,386
  • 4
  • 29
  • 49
Gunnar
  • 18,095
  • 1
  • 53
  • 73
  • 1
    The common solutions are to skip staging (see the accepted answer), but if you skip staging in the last submodule it skips all staging (a serious error in the design of the plugin that has been closed "wontfix" - https://issues.sonatype.org/browse/NEXUS-9138). The backup solution to that problem is to skip the deploy phase in the submodule. I have a situation where I want to deploy the artifact of my last submodule, but not publish it to nexus (it's a war file). The only solution I've found to this is to add a dummy node at the end of the submodule list. – Bretton Wade Jun 04 '23 at 17:18

4 Answers4

4

You can set the configuration property skipNexusStagingDeployMojo of a given submodule to true. See more configuration properties documented in the Nexus book chapter about deployment to staging.

Barry Fruitman
  • 12,316
  • 13
  • 72
  • 135
Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • 5
    This way the artifacts will not get deployed at all if last module/submodule in reactor is skipped. Did not find a way to tell the nexus-staging-maven-plugin to deploy it anyway. Any hints? I do want do skip deployment of two submodules with examples only (visible only as a source). – Pogo19 Jan 26 '15 at 22:34
  • Just set the config parameter only in the modules you want to be skipped and not in the parent.. – Manfred Moser Jan 26 '15 at 23:29
  • That's exactly what I did. No success. – Pogo19 Jan 28 '15 at 12:12
  • any progress on this? I have the same problem that all modules are skipped. Here's my project https://github.com/AKSW/RDFUnit – jimkont Sep 02 '15 at 15:12
  • 4
    This is a sonatype bug, see here for details https://issues.sonatype.org/browse/NEXUS-9138 – jimkont Sep 04 '15 at 08:50
  • Although not an optimal solution, what I did was to try to move at least one "deployable" module after the skipped module, so it's not any more the last module. – Panayotis Jan 22 '23 at 10:18
  • This bug , that cannot skip specific module , it waste me a whole afternoon. – light Aug 09 '23 at 09:42
4

The easiest way I found to deal the limitations of nexus-staging-maven-plugin is to isolate any module you do not want to deploy into a separate Maven profile, and exclude it when a deploy occurs. Example:

<profile>
    <id>no-deploy</id>
    <!--
    According to https://github.com/sonatype/nexus-maven-plugins/tree/master/staging/maven-plugin
    skipNexusStagingDeployMojo may not be set to true in the last reactor module. Because we don't
    want to deploy our last module, nor a dummy module, we simply omit the relevant modules when
    a deploy is in progress.
    -->
    <activation>
        <property>
            <name>!deploy</name>
        </property>
    </activation>
    <modules>
        <module>test</module>
        <module>benchmark</module>
    </modules>
</profile>

In the above example, I avoid building and deploying the "test" and "benchmark" modules. If you want to run unit tests without deploying them, use separate runs:

mvn test
mvn -Ddeploy deploy
Gili
  • 86,244
  • 97
  • 390
  • 689
  • Did you mean "-Pdeploy"? According to https://maven.apache.org/guides/introduction/introduction-to-profiles.html you can activate a profile by using the "-P" flag – Ben McCann Sep 02 '19 at 22:05
  • 1
    @BenMcCann No, I meant `-Ddeploy`. You could use `-Pno-deploy` as you suggest, but in my project I want to active one profile when `deploy` is true and another project when `deploy` is false. Using `-Pdeploy` and `-Pno-deploy` would work but seems needlessly verbose to me. Either approach is valid though. – Gili Sep 03 '19 at 02:09
0

Faced similar problem. Solution that worked for me was adding deployment plugin with skip as true in modules that need to be excluded from deploy task.

           <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-deploy-plugin</artifactId>
              <configuration>
                <skip>true</skip>
              </configuration>
            </plugin>
0

Because all other answers did not quite work for my setup, I endend up with a setup where you can explicitly disable all, but the main module (or in any other combination you like).

Add the followin profile to your main pom

    <!-- this is a workaround to be able to only deploy the main module used in deploy phase, nexus stage plugin is buggy -->
    <profiles>
        <profile>
            <id>allmodules</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <modules>
                <module>modules/module1</module>
                <module>modules/module2</module>
                <module>modules/module3</module>
            </modules>
        </profile>
        <profile>
            <id>mainmodule</id>
            <modules>
                <module>modules/module1</module>
            </modules>
        </profile>
    </profiles>

In this example you only want to deploy the artifact from module1 and you have 3 modules: module1, module2 and module3. Since all modules are active by default, are "normal" maven targets should behave as before. To deploy simply do:

mvn verify nexus-staging:deploy -P !allmodules,mainmodule

which deactivates the allmodules profile, while activating the mainmodule.

Patrick
  • 33,984
  • 10
  • 106
  • 126