Is there an equivalent to a mvn
"deploy:promote"
goal, which will take an artifact from one repository and copy it to another ?
I call this "promote" because the typical use case would be promotion of a snapshot to a release.
I know that proprietary tools exist with UI's for doing this sort of thing.... But I'm assuming that the deploy plugin would handle it as well.
You cannot promote a snapshot to a release.
An snapshot has a version like 1-SNAPSHOT(.complextimestamp)
That version number is in your pom. It's in the metadata in META-INF in your jar or war file. So you can't just copy the artifact and declare that it has a different version.
You must rebuild with the release version and deploy that. The maven-release-plugin and the jgitflow-maven-plugin both automate this process.
Related
If i am deploying a snapshot jar file using mvn deploy, then maven generates the jar file name depending based as follows
projectname-1.0-20170509.204524-1.jar
That is
$project1-$version-$date.$time-$buildnumber.jar
Can i configure maven to use custom jar file name?
Eg projectname-1.0-1.jar, projectname-1.0-2.jar
In your case, the artifact's version is a snapshot. Snapshot artifacts (since Maven 3.x) always must have a timestamped version.
You should not be changing this.
If, you would like to change it for purposes other than for deploying to an artifact repository, I believe you can do this via the finalName, or via the maven-assembly-plugin.
Either way, this is (usually) a very bad idea.
I have trouble understanding, why maven has to check for updates each time we build a project.
The pom has specific version mentioned for each dependency. Once those versions are downloaded to the local repo, then maven can use that local copy to build the project. So why does maven have to check for updates when we build the project each time other than just using the local copy?
a side question.
can a maven artifact be changed after releasing it to a repo under a specific version?
As per Maven, an artifact mainly can be of two types - a RELEASE one and a SNAPSHOT one. RELEASE dependency(eg: 1.0.1, 2.3.0 etc) of an artifact is a source of truth. Means 1.0.1 version of a jar (say test.jar) will always be the same always. We will release artifacts to remote repository, whenever the product matures or after a sequence of bug fixes.
On the other hand, a development is on going in a project, then specified its version number as SNAPSHOT(eg: 2.0-SNAPSHOT, 1.1-SNAPSHOT etc).
Say if we specified test-2.0-SNAPSHOT.jar as dependency in our project pom. If we look at the remote repository (Nexus, archiva etc), we can see that it is not saved as version 2.0-SNAPSHOT rather it will be saved artifact version as date-timestamp-buildnumber format, the date-timestamp at which the artifact was built and uploaded to remote repo. (eg: test-2.0-20150105082634.jar)
So when ever the development team does the fix for an issue on a daily basis the updated jar with date timestamp will be in uploaded to the remote repo. So it is necessary for maven to do look up for the latest date timestamp of SNAPSHOT artifacts. Maven does this by maven-metadata.xml file in the artifact directory in the repo.
Hope this clarifies your query. Let me know, if you need any clarifications
I have a continuous integration build process where each change gets compiled and deployed as a Maven snapshot. When a version is compiled and tested that people are happy with, I want to be able to deploy this to our local Maven repository with a release version.
"The Maven way" to do this would be to take the source again, set a version (versions:set etc), compile and test it all over again then deploy the resulting artifacts. As this process takes some time, I would prefer not to go through all the steps again.
Is there a way of taking the artifacts produced by the first compile step, update the version and deploy them as is without recompiling?
What you believe to be "Maven Way" is not necessarily true. However if you do want to deploy an arbitrary jar as a maven artifact of a different group / name / version you can do so using maven deploy plugin:
mvn deploy:deploy-file -Durl=/path/to/remote/repository -Dfile=/path/to/myjar-1.22.jar -DgroupId=somegroup -DartifactId=yourjar -Dpackaging=jar -Dversion=1.23
The above example will deploy myjar-1.22 as yourjar-1.23 into remote repository.
However you should be cautious about this. Often the original version information is used inside the project itself (as a jar metadata etc)
In my opinion the best way is not to change the version number, but stick to it all the way into the software lifecycle. Utilize source control revision / build number so you always get a unique version label. For example, name your artifact myjar-1.0.3345.23.jar where 1.0 is your major/minor version, 3345 is your source control revision number, and 23 is the build number
Using the maven versions plugin I update the version numbers of the pom files :
versions:set -DnewVersion=1.0.2-SNAPSHOT
I then check in the pom files manually prior to performing a build. I don't think the versions plugin can check in files automatically? The maven releases plugin seems to offer functionalty for checking in files using the 'prepare' goal.
No turns out its only poor mans SCM (stores a backup with the changes you make to the pom and allows you to revert to it).
Use the release plugin.
Is it possible to create a release candidate from my current maven project without changing the version number in the pom.xml?
I just want to build a new maven artifact form my project with a specific version number.
For example: my current pom.xml has the version '0.0.1'. I have called mvn install to create the artifact in my local repository. Now I would like to create a second artifact with the version '0.0.1-RC1'
Is this possible from the mvn command line without changing the version number in my pom.xml?
I would advice against your suggestion of not changing the version number. One of the Maven's benefits is to keep your releases in sequence, i.e. after you have made your '0.0.1-RC1' candidate you will continue to work on the '0.0.1-RC2-SNAPSHOT' version (which may result in a '0.0.1-RELEASE').
That said, you don't have to change the version number manually. The Maven Release Plugin offers great help with this with commands such as mvn release:prepare and mvn release:perform. Also read the Maven build versions in the Maven reference manual. You may also find the discussion about Maven version scheme interesting.
As I see it you have two options:
Embrace the release plug-in. It's been designed to address this problem.
Use the versions plug-in and issue your own source code control commands.