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

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?

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>

Another suggestion could be doing the following:
mvn deploy -pl SubModuleB

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>

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>

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

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>

Related

replace nexus staging maven plugin with maven-deploy-plugin

Our project inherits nexus staging maven plugin from a parent pom which we don't have control on. I have this configuration in my root pom to disable the nexus staging maven plugin and this configuration seems to disabling the default-deploy execution.
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
</executions>
<configuration>
<serverId>nexus</serverId>
<nexusUrl>url</nexusUrl>
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
</configuration>
</plugin>
and I have the maven deploy plugin defined in my root pom, but the maven-deploy plugin seems to be not kicking off
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
I am not able to figure out how i can replace the inherited nexus staging maven plugin with the maven deploy plugin. Any help is much appreciated
You may qualify the goal by the plugin groupID:artefactID:
mvn org.apache.maven.plugins:maven-deploy-plugin:deploy
I faced a similar issue, and for success disabling of nexus-staging-maven-plugin I only need to add following to my main pom:
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<extensions>false</extensions>
</plugin>
And as one of my dependencies was disabling maven-deploy-plugin(I reccomend to check it also in your project) I also need to add:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>

Modifying jar filename using maven

I have a requirement that all the artifacts created by maven bear a build number.
The build number is stored in a properties file. I'm successful with controlling the names of generated EAR and WAR artifacts but not the JAR. Here are the relevant excerpts from pom.xml.
I expected the maven-jar-plugin configuration to work but it does not, I end up with jar always named SelfService-2.jar, whereas when buildNumber.properties contains buildNumber=40, maven generates SelfService-2.40.war and SelfService-2.40.ear.
How do I get the build number into the jar name?
Thanks in advance.
<artifactId>SelfService</artifactId>
<name>SelfService</name>
<packaging>war</packaging>
<version>2</version>
<build>
<finalName>${project.artifactId}-${buildNumber}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<finalName>${project.artifactId}-${buildNumber}</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<finalName>${project.artifactId}-${buildNumber}</finalName>
</configuration>
</plugin>
....
I got what I was after by using the following configuration of maven-jar-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<finalName>${project.artifactId}-${buildNumber}</finalName>
</configuration>
</execution>
</executions>
<configuration>
<finalName>${project.artifactId}-${buildNumber}</finalName>
</configuration>
</plugin>

How to manage artifactory / maven artifact using different profiles

i have some problems understanding how to manage different "jar" files generated using different profiles.
An example. I have a project : my.project:sample:1.0
And we use two profiles:
Using Profile1 is compiling using java 7 and with dependency other:project:1.0
Using Profile2 is compiling using java 6 and with dependency different:project:3.0
Using command line in local environment is easy to manage, but I don't know how to store and manage it on artifactory.
We have two different projects that use the same library but generated using different profiles:
A Project require my.project:sample:1.0 - Profile1"
Another project require my.project:sample:1.0 - Profile2"
How can I specify those depedency with the library and the profile?
Clarification: The generated Jar it's storing using artifactory, and the projects resolve the dependencies using the repository. I can't use the project as a module.
You can use classifier to make the distinction between artifacts and reuse the classifier in the dependency.
defining a classifier
To do so you need to define the classifier in maven-jar-plugin:
<profiles>
<profile>
<id>profile1</id>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>jdk6</classifier>
</configuration>
</execution>
</executions>
<plugin>
<plugins>
</build>
</profile>
<profile>
<id>profile2</id>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>jdk7</classifier>
</configuration>
</execution>
</executions>
<plugin>
<plugins>
</build>
</profile>
</profiles>
using the classifier in dependency
Very simple:
<dependency>
<groupId>myGroup</groupId>
<artifactId>myArtifact</artifactId>
<classifier>jdk6</classifier>
<dependency>

maven goal doesn't execute properly if plugins are defined under pluginManagement

I have maven-jaxb2-plugin. I generate jaxb objects and refer it in other classes of project.I've put jaxb plugin and compiler plugin under pluginManagement tag. Maven is executing compile phase first than generate phase where as if i remove pluginManagement tag, it works fine, first generate phase gets executed and all jaxb object gets generated and then compile phase gets executed. Due to pluginManagement tag, my project doesn't compile. Is pluginManagement tag used only for defining all the plugins in parent pom so that child pom can refer to these plugins ? My project is not a multi-module project.
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/schema</schemaDirectory>
<generatePackage>com.common.dto</generatePackage>
<schemaIncludes>
<include>*.xsd</include>
</schemaIncludes>
<removeOldOutput>false</removeOldOutput>
<strict>false</strict>
<verbose>true</verbose>
<forceRegenerate>true</forceRegenerate>
<extension>true</extension>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Yes, <pluginManagement> is used to create ready-to-use configurations, but does not automatically activate your plugins - you still need to include them.
So in effect you are right, <pluginManagement>, just like <dependencyManagement> are very useful in the parent pom to centralize plugin configurations and dependency management.
Effectively, 'declaring' your plugins in the right module benefits from a much more compact syntax:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
</plugin>
</plugins>

Automatically activate parent plugin in Maven

Is it possible to have a plugin defined in the parent POM which is deactivated, and when the child inherits this plugin it gets automatically activated?
I guess you want to configure the plugin in your parent pom, but use it only in the inherited projects. Maven has a section for this - configure your plugins in pluginManagement, but bind them to a phase just when you needed it, e.g. omit the phase tag in pluginManagement, but specify it under in you inherited pom.
So 'siddhadev' is exactly correct. You can define the plugin configuration in the parent pom with a given id:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>child-caller</id>
<!-- 'phase' omitted -->
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo message="called from child!" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
And, in the child POM, you can explicitly list the phase where this should be called:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>child-caller</id>
<phase>compile</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
I've used this for targeting various JREs. Unfortunately, because you can't use the maven-compiler-plugin with different destination directories (which I consider a bug in the plugin), you must use Ant.
This isn't exactly what you're after, but I think it will work well enough for you.
If you declare the plugin in a pluginManagement tag in the parent, the configuration will be inherited by any child projects that declare that plugin.
For example, in the parent declare that the compile plugin uses Java 5 for test compilation.
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>test-compile</id>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
Then in a child, you simple declare the compiler plugin and the configuration from the parent will be inherited:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
You can declare a plugin at the top level pom and tell it to be skipped and then tell it to not be skipped at the child level. It's not quite automatic, but very minimal in the override verbosity.
Parent Pom, disabling the plugin, but declaring all the config:
<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-surefire-plugin</artifactid>
<configuration>
<skip>true</skip>
...lots more config...
...lots more config...
...lots more config...
</configuration>
</plugin>
Child Pom, enabling the plugin:
<plugin>
<groupid>org.apache.maven.plugins</groupid>
<artifactid>maven-surefire-plugin</artifactid>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
I went with the following solution:
Configure the plugin in the parent-pom in the pluginManagement-section. Bind the plugin to an existing phase.
Deactivate the plugin for the parent-pom by binding it to a nonexistent phase: Override the phase in the plugins-section.
Activate the plugin in each child-pom by including the plugin in the plugins section.
Example parent-pom:
<defaultGoal>install</defaultGoal>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-ejb-client</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${ejb-client-file}</file>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<classifier>client</classifier>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<!-- deactivate the plugin for this project, only child-projects do generate ejb-clients -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<id>install-ejb-client</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
Example child-pom:
<build>
<plugins>
...
<plugin>
<!-- Install the generated client-jar. Property 'ejb-client-file' has to be set! Plugin configuration is in the parent pom -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
</plugin>
...
</plugins>
</build>
As far as I know, there is no generic solution for this. At least for the moment...
One idea (I didn't try it, but it may work) is to define, in the parent pom.xml an execution goal that does not exist, for example:
<executions>
<execution>
<goals>
<goal>noGoal</goal>
</goals>
</execution>
</executions>
and in every child, you redefine a correct goal.
The problem of this solution (if it works, of course ;) ) is that you must redefine the plugin configuration for every child. Otherwise, it will not be executed.

Resources