Maven- Deploy release version of jar - maven

I am new to maven and I'm using the maven release plugin to do a release and the maven deploy to deploy it. What I am noticing is that when I do
mvn release:prepare it makes two commits, as it should be, with the first one being without the snapshot in the pom.xml and then a newer version in the pom.xml with the snapshot. However when I then do mvn deploy it deploys the snapshot jar to my internal repository. How will I get it to deploy the release version of my jar? Should I be checking out HEAD~1 and then do mvn deploy?

Your question is slightly unclear, but the goal to run after release:prepare is release:perform.
Depending on what you're trying to do, the install or deploy plugins may also be useful.
Sonatype, the people that run Maven Central, have a very helpful guide to using the release plugin, as well as other ways of releasing:
http://central.sonatype.org/pages/apache-maven.html#performing-a-release-deployment-with-the-maven-release-plugin

Related

What is the difference between deploying an artifact into Artifactory with 'mvn deploy' command and with Artifactory UI?

I usually use mvn versions:use-latest-versions command to update my dependencies to the latest ones which other teams have been deployed to our free Jfrog's Artifactory server on our local address : http://192.168.100.243:8082/artifactory/X_Douran/.
My problem is when I deploy an artifact (a jar file) with Artifactory UI or with curl (using Jfrog's Rest Api), the command mvn versions:use-latest-versions doesn't work correctly and do not update my pom but when I run mvn clean deploy on my source code of my dependent project then running mvn versions:use-latest-versions on my final project it works correctly and do update my dependency in my pom.
So I want to know what is the different between deploying via Artifactory UI and deploying via mvn clean deploy ?
You always need to deploy the POM along the JAR, otherwise Maven will not work correctly with these dependencies. Furthermore, you need to make sure that the metadata files are updated. I am not sure that Artifactory does this if you deploy using curl or the UI.
Deploying your own JARs regularly through the UI is not recommended. You should build them on a build server (like Jenkins) and then automatically deploy them to Artifactory.
Changing JAR files "by hand" should be forbidden.

Jenkins artifactory release management plugin with mvn versions:use-releases

"mvn versions:use-releases (mvn goals)" remove the "SNAPSHOT" word on your dependencies, ONLY / DURING the specific build you've triggered, not modifying or parsing your pom.xml on the repo itself (like gitlab) this could be very helpful when using artifactory release management plugin because this process doesn't allow projects with SNAPSHOT word on pom.xml, however I have tried using the mvn versions:use-releases when doing a release on artifactory release plugin, but the build is failing due to the build read 1st the pom.xml (with snapshot) before executing the mvn goals that will remove the snapshot word, even I tried to put the mvn goals on the alternative maven goals and options under "enable artifactory release management"
is there any way to solve this?

Maven multi-module project only deploy -SNAPSHOT modules in mvn deploy

I have a snapshot and a release repository defined in the pom.xml of all modules
The modules in my project may be developed and updated independently, i.e. one may be updated (and hence be -SNAPSHOT) during development whereas all others are untouched with release versions
My release nexus repository prevents redeployment
Running mvn deploy will successfully deploy -SNAPSHOT projects to the snapshot repository as required but when it tries to reploy one of the unchanged modules the build fails because that module is already in the release repository
I do not want releases to be redeployable - once a release is deployed it is final
Is there a way to run "mvn deploy" such that all snapshot bundles do get deployed but release modules are skipped?

How does maven handle same version but different jar?

I've a project named main-backend which consume api-backend
I've updated api-backend, and did a mvn install locally so that my main-backend can consume my updated SNAPSHOT jar.
However if someone else pushes api-backend with mvn deploy, what will happen? How does maven determine which SNAPSHOT to use?
the role is if they are snapshots , it will be override
if it is release, it will refuse to deploy to your repo

Build Pipeline with Jenkins - M2 Release -> Deployment to JBoss AS

I am using Jenkins as CI environment and I want to have the ability to deploy the build artifacts directly to a JBoss AS 7.1.1 server. For releasing the Maven artifacts I am using the Jenkins M2 Release Plugin.
The project structure of the project which makes problems looks as follows:
artifact-parent-pom
webapp-module
theme-module
The maven goal jboss-as:deploy can only be called on webapp-module.
To deploy the webapp-module to the JBoss server on every build, I added a post-build step calling
mvn jboss-as:deploy
on the sub-module. This works perfectly for standard SNAPSHOT builds, but not for release builds.
When using the Jenkins M2 Release Plugin to release a new artifact version, the version number is already updated to the next SNAPSHOT-version when the post-build step is executed. I tried to deploy the release version directly at the release step, but this doesn't work, hence the goal jboss-as:deploy cannot be called on the parent-pom.
All Jeknins plugins i have found only support older versions of JBoss like
Deploy to container Plugin
JBoss Management Plugin
Is there an easy way to get this working?
I have found a workaround. I made two configurations, one for the SNAPSHOTS and one for the RELEASE builds. At the RELEASE build I added two post-steps both calling the goal version:set on the parent-pom but with different properties. This results in the following post-steps:
mvn newVersion=${MVN_RELEASE_VERSION}
mvn jboss-as:deploy
mvn newVersion=${MVN_DEV_VERSION}

Resources