I am using the Maven deploy plugin(3.0.0-M1/2.82)
to upload Snapshot jar to Jfrog Artifactory, but Plugin builds the SnapShot jar with the timeStamp and build Number(Default Behavior Of Maven Build with Timestamp while Remote Repository ) and says it uploading with name
example: project-extension-0.0.2-20200506.171928-1.jar but it uploads with SnapShot
name: project-extension-0.0.2-SNAPSHOT.jar(0.0.2-SNAPSHOT its Parent POM Version ) and replace it with the previous build Jar.
This is how SNAPSHOTs work.
The file is uploaded with a timestamp name (and also saved as such internally). But usually just specify the version as 0.0.2-SNAPSHOT and Maven resolves the latest timestamp for you.
Artifactory keeps the different versions, but can be configured to keep only the last n SNAPSHOTs.
Related
It looks like mvn install:install-file is for downloading a jar to a specific location.
I just want to manually download some publicly accessible dependencies to my local Maven cache (specifically the help and versions plugin). It doesn't have to be specific versions, just the latest versions is fine
I want Maven to install them just like it would with the install goal but just execute this from command line without a pom. Is this possible?
If you don't want create a pom.xml then you can use download-maven-plugin's artifact goal as shown in the below example.
You need pass groupId, artifactId and version. It
can't download the file if any one of these 3 are missing or not
matching with central repo. If you don't want to download pom file, you can ignore the second line.
Example:
mvn com.googlecode.maven-download-plugin:download-maven-plugin:1.4.2:artifact -DgroupId=log4j -DartifactId=log4j -Dversion=1.2.4 -Dtype=jar -DoutputDirectory=C:\Temp
mvn com.googlecode.maven-download-plugin:download-maven-plugin:1.4.2:artifact -DgroupId=log4j -DartifactId=log4j -Dversion=1.2.4 -Dtype=pom -DoutputDirectory=C:\Temp
This will download both JAR and POM files for log4j:log4j:1.2.4 from central repository to your local repository and also copies the files to C:\Temp folder. Once you are done downloading all the files, you can delete the Temp folder.
In Our Project Nexus is used as Jar repository and we are having the below entry in the settings.xml .
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://*.*.*.*:7003/nexus/content/groups/public</url>
</mirror>
When ever a new jar is loaded in nexus it is uploaded in the path as per the entries present in the pom.xml .
<dependency>
<groupId>com.pqr.xyz.abc</groupId>
<artifactId>xyz</artifactId>
<version>2.2.0.0.4.1</version> OR <version>LATEST<version>
</dependency>
So, if the jar is uploaded in nexus every time with a new version then the it is getting picked when we are doing the maven update for our project which is having the entry of the version as mentioned above (either the specific version or LATEST.
But if we update the same version folder in nexus with the updated jar then maven update is not picking the latest jar, it keeps the old jar in the .m2 repository even if we do force update then also.
So we think that if the jar is replaced in the same folder in nexus then it will not be updated if the folder already exists in .m2 repository?
Is there any way to take the latest jar every time even if the same folder is updating in nexus via maven update?
You have a misunderstanding of maven concepts regarding versioning of artefacts. There is a big difference between SNAPSHOT and release versions and I suggest to read these documentations: Release and Snapshot and Repositories settings
Back to your issue, the solution is to remove from your local maven repository the artefact that was updated on nexus. You have 2 options:
List item manual delete the folder ${user.home}/.m2/repository/com/pqr/xyz/abc/xyz/2.2.0.0.4.1/ (this assume your local repository in under your home directory)
Use dependency plugin - purge local repository to remove local artefacts. You can find an example here
In your expose you didn't mention why you have to update a release jar in nexus. Conceptually, this smells. I advise to reconsider your release procedure and to avoid updates on releses versions. It's better to create a patch/minor version instead of updating a release. Put in place of a client, when a client should check if a release was updated and based on what? A downloaded file timestamp is not reliable.
I have set up Jenkins with the Multibranch Pipeline plugin, and I have configured it to trigger a build when there is a commit in a GitHub repository. I want to copy the .jar file, that is created by the maven build to a custom directory. To do that I have to specify the name of the file. The problem is that the name of the file contains the artifactId and the version from the pom.xml file. And the version changes quite often.
Is there a way to get the artifactId and version in Jenkins from the pom.xml file? I have red this blog post, but it says that these Jenkins variables work only if I create a Maven project in Jenkins.
You can do:
pom = readMavenPom file: 'pom.xml'
pom.artifactId
pom.version
You will need Pipeline Utility Steps plugin for this to work.
Env : Maven 3.3.9
Hi,
I have a maven jar module with version as 1.0-SNAPSHOT. When i do mvn install, the jar installed into local repository (~/.m2/repository) does not have timestamp. I agree that its not a common scenario where you would like to have timestamped jars in your ~/.m2/repository repo. But still couple of questions:
Does mvn install append timestamp automatically? Looking for some
configuration way rather than use ${timestamp} in final name.
Does automatic timestamp mechanism applies to mvn deploy?
Is there a way to tell maven to use ~/.m2/repository
itself for mvn deploy?
Thanks,
Rakesh
The mvn install will only put your project into your local cache which means it makes it available for other projects on your machine.
mvn deploy will deploy the artifacts into your remote repository which is usually a corporate repository manager.
In case of a SNAPSHOT this means this artifact has not been finalized and is under developer. This means you can create several states of the same version like 1.0.0-SNAPSHOT. The time stamp which is created during the deployment to a repository manager is intended to have different artifacts available for development. You can control via -U option if you like to use the most recent version of the SNAPSHOT's.
After you feel ready you make a so called release which will set the version to something like 1.0.0 (without SNAPSHOT) which is deployed as well but into a release repository which is immutable.
Furthermore having timestamps in your local cache $HOME/.m2/repository does not make really sense, cause you can control when you install an artifact there and no one else and you should prevent using finalName change cause this is only intended for your target folder and not for your local cache.
And finally using the local cache for mvn deploy does not make sense, cause what is the idea behind that? Best is to start using a repository manager like Nexus, Artifactory or Archiva in particular if your are working in a corporate environment.
In addition to #khmarbaise's answer see the following references:
Maven / Introduction to Repositories:
There are strictly only two types of repositories: local and remote. The local repository refers to a copy on your own installation that is a cache of the remote downloads, and also contains the temporary build artifacts that you have not yet released.
Remote repositories refer to any other type of repository, [...]
Maven: The Complete Reference, 15.2.8. Repositories:
Repositories are remote collections of projects from which Maven uses to populate the local repository of the build system.
Repository - SNAPSHOT Handling reads:
This documentation was targetted at Maven 2.0 alpha 1. It is here only for historical reference and to be updated and integrated into the Maven documentation.
But I didn't find any latest documentation where this has been integrated. (#khmarbaise?)
Timestamped files are not created on install in the local repository for reasons of disk space preservation. However, when a SNAPSHOT is resolved and downloaded, it is saved with its timestamp version number (eg: 0.15-20050401.150432-2).
Understanding Maven Version Numbers
Maven Dependency Resolution - A Repository Perspective
Long story short:
The same snapshot version can be deployed to a remote repository from different hosts, so they have to be distinguished there somehow. And they are distinguished by timestamps (and a build number).
There will be an artifact with a timestamp (and build number) in the local repository only if Maven resolved and, hence, downloaded it from remote.
So:
No.
Yes.
Would break Maven's repositories handling of local vs. remote.
I have several libraries which I've manually deployed to my Nexus repository using:
mvn deploy:deploy-file -Durl=[url] -DrepositoryId=[repoId] -Dfile=[filePath] -DgroupId=[gId] -DartifactId=[aid] -Dversion=[v] -Dpackaging=jar
I did this because they are legacy jars and quite a large amount of them for which I've automated the process.
The problem I'm having is in packaging a WAR. The dependencies come down just fine, but when the war is generated they have the version+timestamp appended to the end. I have several other projects where this doesn't appear to be the scenario - i.e., after multiple packagings and deployments to a given server the lib directory [for the project] contains:
[jar].[<version>-timestamp1].jar
[jar].[<version>-timestamp2].jar
[jar].[<version>-timestamp3].jar
[jar].[<version>-SNAPSHOT].jar <== this entry alone would be ideal
Also, I'm not using any specific plugins just invoking:
clean package
Is it possible to eliminate the timestamp when packaging the war?
You may need to ask yourself why you need to eliminate the timestamp.
If you just want to download the latest SNAPSHOT version, Nexus provides REST API to download latest SNAPSHOT artifact just directly using your snapshot version as version parameter, such as 1.0-SNAPSHOT. e.g.
http://<your-nexus>/service/local/artifact/maven/redirect?r=<your-repo>&g=<the-group>&a=<the-id>&v=1.0-SNAPSHOT
From the API doc, the version parameter can support LATEST, RELEASE and SNAPSHOT versions.
Version of the artifact (Required) Supports resolving of "LATEST", "RELEASE" and snapshot versions ("1.0-SNAPSHOT") too.
Furthermore, with timestamp each SNAPSHOT build has it's unique version, which gives you the chance to download a specified SNAPSHOT build such as v=1.0-20140822.145007-2.
If you want to limit the number of snapshots, you can take a look this one: How to limit number of deployed snapshots artifacts in Nexus?