Gunnar
Gunnar

Reputation: 18970

How to disable nexus-staging-maven-plugin in sub-modules

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).

Upvotes: 18

Views: 5994

Answers (5)

Stefano Cordio
Stefano Cordio

Reputation: 2247

The following worked for me in cases where the last submodule should not be deployed, without requiring profiles.

At first, the nexus-staging-maven-plugin should be declared in the pluginManagement section of the root POM, with its configuration:

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.sonatype.plugins</groupId>
        <artifactId>nexus-staging-maven-plugin</artifactId>
        <version>${nexus-staging-maven-plugin.version}</version>
        <extensions>true</extensions>
        <configuration>
          ...
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
  ...

Then, the plugin is declared again in the root POM, under the plugins section, but with inherited set to false:

  ...
  <plugins>
    <plugin>
      <groupId>org.sonatype.plugins</groupId>
      <artifactId>nexus-staging-maven-plugin</artifactId>
      <inherited>false</inherited>
    </plugin>
  </plugins>
</build>

Lastly, the plugin declaration is added only to the POM of the submodules to be deployed:

<build>
  <plugins>
    <plugin>
      <groupId>org.sonatype.plugins</groupId>
      <artifactId>nexus-staging-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>

Real-life example from AssertJ:

Upvotes: 1

Patrick
Patrick

Reputation: 35224

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.

Upvotes: 0

Gili
Gili

Reputation: 89993

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

Upvotes: 4

amaan qureshi
amaan qureshi

Reputation: 1

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>

Upvotes: 0

Manfred Moser
Manfred Moser

Reputation: 29912

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.

Upvotes: 6

Related Questions