Can i configure maven to use custom build number for Snapshot version - maven

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.

Related

Can I avoid Maven deployed war version with timestamp in Archiva?

In out project we are using using deployed war file in /archiva-2.2.0/repositories/internal/com/xyz/1-SNAPSHOT/proj-1-20160204.122021-15.war path using shell script to copy to jboss. However finding the latest build timestamp and build number is very difficult. Is there a way to avoid using timestamp while storing it in archiva like proj-1-SNAPSHOT.war?
I have already read about <uniqueVersion>false</uniqueVersion> whcih is not supported in maven 3.
I am using archiva-2.2.0, maven-3.3.9.
Maven repositories wasn't designed to distribute deployable components, your continuous integration environment should take care of this. Jenkins has eg Archive Artifacts (native) and Copy Artifact Plugin which you can use to store and recover binaries in your pipelines.
But you can workaround this behavior changing the version of the war to a stable one - removing the -SNAPSHOT suffix. This will lead you with a predictable URL.
I am posting this as it is a new finding, if I wget http://xx.xx.xx.xx:8083/repository/internal/com/xyz/1-SNAPSHOT/proj-1-SNAPSHOT.war. I get the latest deployed artifact in the archiva repository. So archiva does a 302 redirect to point to url of http://xx.xx.xx.xx:8083/repository/internal/com/xyz/1-SNAPSHOT/proj-1-20160204.122021-15.war location and downloads the latest build. I am not sure if this works for other repositories like nexus or artifactory etc.
Ofcourse I will need a cron job to periodically clear of the stale snapshot artifacts.

Maven WAR Plugin / Jenkins repository connector: Omitting transitive dependencies?

Situation
I have a multi-module Maven project. In it, I have several JAR artefacts, it then gets assembled as a WAR file. Thus, the WAR artefact depends on all kinds of JAR artefacts (it also has a WAR overlay), most of them with scope "compile".
Build and deployment to a repository are fine. But when I try to retrieve the WAR artefact, I have issues. previously, I used a simple wget to retrieve it from the Nexus API, but I wanted to try the Jenkins Repository Connector - not the least reason being that it actually shows a list of available versions.
I configure a repository in
Manage Jenkins -> Configure System -> Artifact Resolver
with the URL for our repo:
http://$NEXUS/nexus/content/repositories/releases/
then in the job, i add a parameter:
Maven Repository Artifact
and use the repository configured above, then i add
Artifact Resolver
as a build step and set it up.
Problem
I am not even sure on which side this should be solved: When I run the job to try to get the WAR file from the nexus, it also starts trying to retrieve all kinds of transitive dependencies (some of which are unaccessible to this user) and fails. What I need is just the WAR file. No transitive dependencies (since they're already packaged in the WAR).
The Repository Connector plugin doesn't seem to have a switch for this, and the Maven side it's probably perfectly OK to include those dependencies in the output POM.
Question
What can I do to either stop the repository connector from retrieving transitive dependencies or retrieve the WAR artefact in a different way? Also interesting for me (but a bit broad as a question) would be general ideas about doing this kind of workflow. E.g., does anyone use other ways of deploying the WAR into their Nexus?
i submitted a patch to the repository connector plugin.
my fork:
https://github.com/rmalchow/repository-connector-plugin
working on getting it to be merged:
https://github.com/jenkinsci/repository-connector-plugin/pull/10

The equivalent of a maven "promote" goal

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.

Do not want version number on my jar/ear/war while using maven to deploy to nexus

I have an ant build invoked my jenkins that creates my .ear/.war file but using maven in jenkins to upload archive to Nexus for deployment tool to use.
The archive from ant is titled myear.ear but ends up as myear-version.ear in nexus upon deploy.
I do not want the version number added to the artifact - Any way to avoid this behavior?
Thank You!
The artifact in the Maven repository will always contain the version number as part of the filename since that is part of the Maven repository format. The filename is artifactId-version[-classifier].packaging.
However that is never really a problem because nothing stops you from downloading it following that naming convention and then changing the name of the downloaded file. And if you dont know the version you can query Nexus for the available versions via the REST API.
You can add the finalName configuration inside your pom as below
<build>
<finalName>desiredName</finalName>
</build>

deploy on nexus artifacts with Snapshot policy but without SNAPSHOT string in version

apparently my Nexus is rejecting every deploy I throw at him if the artifact has not -SNAPSHOT in the version.
Data:
name of the failing artifact: entando-core-engine-experiment-bundles_with_bootstrap.jar where experiment-bundles_with_bootstrap is the version as in the version element of the pom.xml
hosted repository policy on my Nexus: Snapshot, allow redeploy and so on (classic conf for snapshots)
deployer: Jenkins 1.481
same Jenkins job, but entando-core-engine-SNAPSHOT.jar ---> SUCCESS
I need this naming convention because I'm building one of the several experiments we run internally, as opposite to the canonical develop branch which produces a proper entando-core-engine-SNAPSHOT.jar
Any advice?
I'm totally lost.
The thing is that usually your Nexus is configured not to allow a redeployment of a release. A release from Maven point of view is an artifact where it's version it NOT -SNAPSHOT. In contradiction a SNAPSHOT is intended to be deployed several times into nexus.
This sounds like you don't using the release plugin of Maven nor the Release PLugin of Jenkins.
Nexus is a repository manager that uses different repository formats, with the main format being the Maven repository format. Changing the names of artifacts on the server is not possible since it violates the format. They have to be located in the directory structure established by groupId, artifactId and version and use the artifactId-version-classifier.packaging for the file names.
If you need a different file name on the server you have to look at a different repository format (bad idea). If you need the filename on the client just download from the correct name and rename..

Resources