How to Deploy only the sub-modules using maven deploy?
Asked Answered
F

7

58

How do i deploy only the sub-modules of the project? i have a project as;

ProjectA
 -  Submodule B
 - Submodlue C
 - Submodule D 

The submodules are packaged as jar and is deployed to maven repo.how can only the sub -modules be deployed to the maven repository and not the main project?

Fecundity answered 16/9, 2011 at 14:59 Comment(0)
U
84

Put this in module(s)(or module's pom.xml) that you don't want to deploy:

<properties>
  <maven.deploy.skip>true</maven.deploy.skip>
</properties>

Since this is inherited by submodules, you have to put this in submodules that you do want to deploy:

<properties>
  <maven.deploy.skip>false</maven.deploy.skip>
</properties>
Uzzial answered 11/4, 2015 at 6:21 Comment(3)
The skip property will be true in all submodules... so nothing at all will be deployed....Invaluable
@Invaluable just set the skip property to false for all the submodules you want to deploy...Outstretch
Also if you have a situation where you need to deploy overlapping sets of module, use profiles. Example: module is [m1, m2, m3] user setting-foo deploy[m1, m2] and under 'setting-bar' deploy[m2, m3] ref: maven-profilePellucid
G
19

Another suggestion could be doing the following:

mvn deploy -pl SubModuleB
Gadfly answered 24/3, 2020 at 16:4 Comment(3)
This is very simple and easy solution.Afterthought
This way the parent pom is not published and causes the project who references the module to fail when buildingTecu
You would also get Could not resolve dependencies for project if SubModuleB is depending on any other module (eg. Submodlue C).Springhead
P
12

This is working on my side Put the plugin declaration in the parent pom , skip=true, but set inherited=false. This prevents from repeating the <maven.deploy.skip> on each child modules.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8.2</version>
    <configuration>
        <skip>true</skip>
    </configuration>
    <inherited>false</inherited>
</plugin>
Pacemaker answered 9/3, 2020 at 13:50 Comment(0)
C
10

This worked for me. Similar to other answer except added missing plugins element. Add to parent POM.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>
    </plugins>
</build>
Criswell answered 1/10, 2013 at 1:1 Comment(1)
You also need to re-enable the deploy for each sub-module that you want to deploy with a <skip>false</skip>Unpeopled
D
9

You can use the technique described in my blog.

In this case, you'd disable default-deploy (or what the name is) in the root pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <executions>
        <execution>
            <id>default-deploy</id>
            <phase>none</phase>
        </execution>
    </executions>
</plugin>

And then enable it for submodules:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <executions>
        <execution>
            <id>default-deploy</id>
            <phase>deploy</phase>
        </execution>
    </executions>
</plugin>
Duckworth answered 13/7, 2013 at 6:25 Comment(0)
A
1

You can configure the maven-deploy-plugin in the POM of a module to exclude it from the deploy:

<build>
  <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-deploy-plugin</artifactId>
     <version>2.4</version>
     <configuration>
       <skip>true</skip>
     </configuration>
   </plugin>
   ...
</build>
Alpha answered 21/9, 2011 at 14:23 Comment(1)
Hi Raghu ...couldnt make it work ...tried putting the code into parent pm,but it gives the same resultFecundity
W
0

First, build the whole project locally mvn clean install ,then cd to where the module is ProjectA -> Submodule B, and run deploy command:

I-am-in-Submodule-B-directory$ mvn -DskipTest deploy
Wrasse answered 9/9, 2024 at 15:39 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.