disable maven release plugin defined in parent pom - maven

I am new to maven. I have product structure as following
myWebProduct
pom.xml
coreModule
webModule
htmlTestModule
The maven release plugin is defined at the company level of pom.xml file which is parent of myWebProduct. It has set release plugin run default goals of deploy and default preparationGoals clean verify install.
I want to release product in myWebProduct level which works fine except I would like to skip release the htmlTestModule. Because deploy life cycle on htmlTestModule will cause deployment of war file to remote Tomcat servers and I don’t want this happening during release.
I tried to add following in pom.xml of the htmlTestModule.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
<configuration>
<skip>true</skip>
<preparationGoals>clean validate</preparationGoals>
<goals>testCompile</goals>
</configuration>
</plugin>
But when running 'mvn release:perform' at myWebProduct. I have seen the deploy goal was still executed on htmlTestModule. Could anyone help with this?
And I also tried following on htmlTestModule:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>donotRunMe</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
Still, the deploy goal always executed in htmlTestModule.
Thanks

I think you're taking the wrong approach here. Let me explain.
The deploy phase of maven is not meant to mean deploy to a remote server or anything like this. This is meant to be deploy to a remote repository.
Hence I believe you shouldn't try to skip the deploy phase in your module, but un-tie the deployment to a remote Tomcat server from the deploy phase, by making it a specific goal for example.

Related

Preventing Maven Modules from being Deployed

I followed this tutorial to created a Maven build that can publish artifacts to Maven Central.
It works, and most of the tutorial is for authentication of some sort, so the only relevant part of it might just be:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
Now I wanted to only deploy two of the seven modules in total, so I added this to the parent POM:
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
And <skip>false</skip> to the two modules I actually want to deploy.
This doesn't work. All modules get deployed.
I checked the effective POM, and it clearly shows skip=false for the two modules I want to deploy and skip=true for the other five modules.
Since deploying to Maven Central isn't really a reversible process, I don't want to trial and error my way through this problem, hence the question: How do I prevent Maven modules from deploying to Maven Central?
If you are deploying to Maven Central, it is the Nexus Staging Plugin that is doing the deployment instead of the Deploy plugin, so the configuration of the deploy plugin has no effect. To make the Nexus deploy plugin skip, set skipNexusStagingDeployMojo in its configuration to true.
For a complete example, you can look at one of my projects I deployed to Maven Central with the same problem - I want to deploy everything except the integration test modules.
In the parent POM, the Nexus deploy plugin is defined like normal as described in the tutorial (https://bitbucket.org/prunge/shoelaces/src/2347535282c9f5bb58d33cca22d9dd65c9db2c2b/pom.xml#pom.xml-200):
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
and in the integration tests project (which itself has children that inherit this configuration) the staging plugin is skipped (https://bitbucket.org/prunge/shoelaces/src/2347535282c9f5bb58d33cca22d9dd65c9db2c2b/integration-tests/pom.xml#pom.xml-28):
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
</configuration>
</plugin>
This results in everything by default being deployed to Central except the integration tests project and everything underneath that.

Simultaneously deploy artifact to Maven Central and internal Nexus

I have a project which deploys to Maven Central via OSSRH using the Maven release and nexus-staging-maven plugins using the directions from http://central.sonatype.org/pages/ossrh-guide.html and http://central.sonatype.org/pages/apache-maven.html .
This works fine, but it often takes several hours for the artifact to be visible on Maven Central. Often we would like to make use of the deployed artifact immediately, so we end up deploying it from our local repositories to our internal Nexus server using deploy:deploy-file . This works but it is inelegant and easy to forget to do. Is there any way to make Maven deploy to an internal Nexus as well as Maven Central as part of the release process?
Note: This question is similar to, but not quite the same as, https://stackoverflow.com/questions/29019682/promote-artifact-from-internal-nexus-repository-to-maven-central
Add an additional execution to the maven-deploy-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven.deploy.plugin.version}</version>
<executions>
<execution>
<id>nexus-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<altDeploymentRepository>yourNexusRepo</altDeploymentRepository>
</configuration>
</execution>
</executions>
</plugin>
The yourNexusRepo value will look something like this:
releases::default::https://nexus.host.org/nexus/content/repositories/releases
You should be able to get the exact URL from Nexus. The part before the first :: is the repository ID.
We solved this problem by no longer using nexus-staging-maven-plugin as an extension. This is described at https://help.sonatype.com/repomanager2/staging-releases/configuring-your-project-for-deployment :
If more control is desired over when the plugins deploy goal is
activated or if Maven 2 is used, you have to explicitly deactivate the
Maven Deploy plugin and replace the Maven Deploy plugin invocation
with the Nexus Staging Maven plugin...
In our case, we disabled the default-deploy execution by setting <phase>none</phase>. Our full solution is available at https://github.com/newmediaworks/nmw-oss-parent/commit/a7377a158feded473cb2f1618449e34173c22252 which includes an additional execution of maven-deploy-plugin in the jenkins-deploy profile.
The key takeaway follows, which so far seems to behave as if extension were enabled, but does not interfere with additional maven-deploy-plugin executions:
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId><artifactId>nexus-staging-maven-plugin</artifactId>
<!--
Not using as extension, since it blocks maven-deploy-plugin in the jenkins-deploy profile:
<extensions>true</extensions>
-->
<executions>
<execution>
<!-- Manually added since nexus-staging-maven-plugin is not used as extension -->
<id>default-deploy</id><phase>deploy</phase><goals><goal>deploy</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId><artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<!-- Manually disabled since nexus-staging-maven-plugin is not used as extension -->
<id>default-deploy</id><phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>

Deploying maven project to nexus server using git-describe plugin output

I have several maven projects that deploy to a nexus server. I don't like managing their versions via the pom file, and already use git tags for versioning via git-describe.
I added the git-describe maven plugin with the following config:
<plugin>
<groupId>com.lukegb.mojo</groupId>
<artifactId>gitdescribe-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<goals>
<goal>gitdescribe</goal>
</goals>
<id>git-describe</id>
<phase>initialize</phase>
<configuration>
<outputPrefix></outputPrefix>
</configuration>
</execution>
</executions>
</plugin>
and it works perfectly for mvn package runs - but when I use mvn deploy I end up seeing:
nexus/content/repositories/releases/me/botsko/project/${describe}/project-${describe}.jar
I tried to talk to the plugin author but it's been a few days and no reply.
How can I modify the plugin, or my configuration to property set the version during the deploy phase?
There may be a way to edit the plugin but I'm not familiar with how the maven plugin architecture works.
I solved the problem by writing a shell script that passes the same git-describe value to the maven deploy process:
#!/bin/sh
gitvers=`git describe`
mvn deploy -Ddescribe=$gitvers-SNAPSHOT
Just make sure you use <version>${describe}</version> or similar in the POM.

Maven release plugin: How to deploy only a distribution jar on release:perform

I have a multimodule project, and the last module being built is a distribution zip of the application.
core/
plugins/
plugins/logger
plugins/social
...
assemble/
I want to distribute the application in the form of Maven artifact. And I don't want to deploy the modules artifacts with it.
But the release plugin needs to run from the root (I want to do all the usual stuff like updating versions, tagging, commits these changes etc.)
What is the way to tell the release plugin which artifacts to deploy?
Note that this is different from limiting only the deploy plugin, because release plugin seems to call the deploy plugin in certain internal way. (Not sure about that.)
Seems like the Release plugin behavior was fixed and it now properly invokes deploy:deploy.
So I used my standard trick to suppress default plugin execution. Root pom.xml:
<!-- Don't deploy all artifacts. Overridden in submodules. -->
<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 the dist module pom.xml:
<!-- Enable deploy for this submodule. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions> <execution> <id>default-deploy</id> <phase>deploy</phase> </execution></executions>
</plugin>
The release:perform isn't doing that much magic. It checks out the code by the tag which was created during release:prepare. The default goal is 'deploy'. If you have specified a site within the distributionManagement of the pom.xml it'll be 'deploy site-deploy'. These steps could also be done by hand.
If you never want to deploy these artifacts (not during developerment nor release), I'd prefer the skip over using an undefined phase.
If this is only required during a release, you should specify this within a release-profile.

Multi-module maven : test coverage jacoco sonar

I have a basic maven multi-module, with a parent being the POM and three children modules : domain, service and web.
I have added in the pom parent the jacoco plugin and the required configuration to append the test coverage report to a single file easily located by sonar.
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.2.201302030002</version>
<configuration>
<destFile>${project.basedir}/../target/jacoco.exec</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
My issue is that Sonar shows only the test coverage of the first module (being domain) (even though I open the file with an editor and I see the class names of the others modules being append in it.
What could wrong in this configuration ?
For what it's worth, sonar analysis is called from Jenkins, and not from mvn sonar:sonar
Jenkins configuration is the key : There is no need to append everything in a single file when the configuration is right.
I added this to the config :
sonar.modules=xxx-domain,xxx-service,xxx-web
and I deleted the configuration tag in the pom.xml given in the question.
It works like a charm
For those who struggle with this, look for anything useful to specify the jenkins project configuration for sonar
You can check our sample application here: https://github.com/SonarSource/sonar-examples/tree/master/projects/code-coverage/ut/maven/ut-maven-jacoco-runTests
You should be able to find what's wrong with your configuration then.

Resources