Skip maven deploy for one module
Asked Answered
M

1

9

I have a multi-module maven project. Parent pom looks like this:

<project>
    ...
    <packaging>pom</packaging>   
    <modules>
        <module>common</module>
        <module>a</module>
        <module>b</module>
    </modules>
</project>

common builds a jar, which is added as dependency in the other modules, like this:

<dependency>
    <groupId>my.project</groupId>
    <artifactId>common</artifactId>
    <version>${module.common.version}</version>
</dependency>

Modules a and b are Spring Boot projects having the spotify docker plugin.

I need to be able to run mvn deploy in order to get the spotify plugin push the docker image.

mvn install works fine, which builds the docker images. But in order to push them, when I run mvn deploy, it throws error for the common module:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project common: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter

Searching for this error, this answer suggests adding the repository url in the distributionManagement section. But I don't want to deploy common. I just want to build it, so it gets injected as dependency in the other modules and deploy those other modules. How can I do that?

I tried to deploy only a and b using this command, but it gives the same error for common:

mvn clean \
   -DdockerRegistryHost=123.dkr.ecr.us-west-1.amazonaws.com/test1 \
   --projects a,b \
   --also-make \
   deploy
Mucosa answered 24/5, 2019 at 1:42 Comment(3)
Do you want to set this module to never deploy?Han
@chrylis Sure, it's not supposed to be deployed, just added as a dependency.Mucosa
Have you tried configuring the maven-deploy-plugin to executions=none?Han
M
16

You can accomplish what you want by configuring the maven-deploy-plugin.

Try adding the following to your parent pom:

<build>
    ...
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>3.0.0-M1</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    ...
 </build>

or add -Dmaven.deploy.skip=true to your command line.

Moneybag answered 24/5, 2019 at 2:54 Comment(7)
Thank you. Any reason for specifying a version here? If we don't specify it, does it pick up the latest version just like any other dependencies?Mucosa
No it does not. Always specify plugin dependencies for repeatability.If you do not specify a plugin version then you will get the one that is associated with the particular version of maven that you are using. Also, I don't believe that "pick up the latest version just like any other dependencies" is a thing either.Moneybag
@steve how maven will come to know what artifacts to skip upload?Cogitative
@SteveC how can I skip maven deploy for a specific module at runtime using -Dmaven.deploy.skip=trueIago
@RishabPrasad, I don't think you can do it that way. You would need to use a profile to do this.Moneybag
Just to understand this right, will this skip deployment for the parent or for all projects? I would like to skip deployment in the parent pom itself, so that only the modules will be deployed while using mvn deploy. It currently errors out in parent due to lack of the distributionManagement option.Jumbled
@Andre_601, this configuration applies to all modules including the parent. If you want maven to deploy a particular module to a maven repo then you can add the above declaration (without the pluginManagement elements) and set <skip>false</skip>.Moneybag

© 2022 - 2024 — McMap. All rights reserved.