How maven decides to reference the latest artifact information - maven

We use mvn deploy:deploy to deploy an artifact to repository manager and a developer could have done just mvn install for the same artifact, so the artifact is present under M2_HOME\.m2\repository
Will the maven runtime retrieve the artifact from the repository manager if it was updated recently than the local repository copy?
Note: We use a maven repository manager based on Apache Archiva.

The answer depends on whether you're talking about a snapshot or a release build.
Release builds have a version that doesn't end with "-SNAPSHOT", and they're final and immutable. Once installed to any repository, Maven will never update them. To your question, that means that if a dev installs a release build locally, it will never be updated from any remote repository.
Snapshot builds are always eligible to be updated from any repository. By default, Maven checks once per day for new snapshot versions, so if someone installs a snapshot locally, that snapshot will exist until Maven does its next check for snapshot updates. Then, if a newer version is in any remote repository it checks, the local one will be overwritten. You can force maven to update snapshot artifacts with the -U command line option.

Related

How to delete old repository before uploading new repository on nexus

How to delete old repository before uploading new repository on remote repository of nexus repository manager OSS 2.12.0-01,
i am using
mvn clean install
and
mvn clean deploy ?
You are deploying artifacts not repositories.
You should never delete your uploaded artifacts and in case it's not your server you just can't delete it. Published artifacts could already be consumed be third parties and thus mustn't be deleted.
But you can release your artifact as a SNAPSHOT version. In that case you can upload a new version of your artifact any time without changing the version.
All you have to do is append '-SNAPSHOT' to the artifact's version like
< version>1.0-SNAPSHOT< /version>
EDIT:
If you really, really want to delete artifacts on your server this answer should help you.

Maven - Why Does it Keep Redownloading Dependencies?

When I add a new Maven dependency that I've never used before, I will do Maven build and see the dependencies being downloaded into my local machine from Nexus. All is good.
I will then create another project, specify the same dependency with the same version, do a Maven build, and I will again see the dependencies being downloaded from Nexus into my local machine.
Why are my dependencies re-downloaded every time? Aren't these dependencies already installed in my local repository?
Maven will NOT download artifacts repeatedly. The only exceptions are if you are deleting your local repository (in ~/.m2/repository by default), you are configuring usage of a different local repository and if a new SNAPSHOT version is available.

why does maven check for updates when I have specified a version?

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

Importing a snapshot version of a dependency into Maven repository

I am having trouble importing dependencies for my Grails project into the company Nexus repository. The Grails plugin I would like to use is events-push (https://github.com/smaldini/grails-events-push). The latest released version of the plugin is 1.0.M7. It uses a very old version of Atmosphere library. The GutHub repository contains a more up-to-date version of events-push plugin, 1.0.0.BUILD-SNAPSHOT. I built the Grails plugin from the local clone of the repository and got it to work in my dev environment.
To deploy it on the intranet (in the production environment) I need to import all the plugin dependencies into the company Nexus repository. This is where I run into trouble. The project depends on a SNAPSHOT version of events-push plugin, which in turn depends on SNAPSHOT version of other Grails plugins and Java libraries (according to dependency report).
Nexus supports two types of repositories, Release and Snapshot. I can add artifacts to a Release repository (through the browser UI or in a batch mode using curl), but the artifact must not be a snapshot. I can change the repository to be a Snapshot repository, but then I lose the ability to add artifact to it through the browser or curl command.
How do I make these SNAPSHOT artifacts available to the Grails project through Maven?
Change them to a release version and deploy them to the release repository.

How to do remove a projects artifacts from the local maven repo?

When running mvn install on a local multi module project it builds and install the projects artifacts into the local repo. mvn clean seems to clean up my project specific target directories.
What command do I use with maven to get it to uninstall my projects modules from the local repo? for example my projects outputs foo-0.1.jar and bar-0.2.jar I want those removed from my local repo without having to go in there and delete them myself.
mvn build-helper:remove-project-artifact
You can purge artifacts from your local repository, but why do you like to do this? Apart from that you can do that via maven-dependency-plugin:
This will purge all project- and dependency artifacts
mvn dependency:purge-local-repository -DreResolve=false
This can be influenced by supplemental command line arguments (see the documentation) for further details.
Best is to implement a release strategy, i.e. as long as the artifacts under development appending the version with SNAPSHOT. Maven then automatically updates the artifacts in the local repository when you run install. Once you have completed the development you remove the SNAPSHOT and release the version (i.e. via deploy). If further development is required you could increase the version number and append it again with SNAPSHOT.

Resources