what is the difference maven generating artifacts from cache and updates - maven

I would like to know the difference between generating artifacts from and cache and updates.
Does generating artifacts get from remote repository if it is not available in local repository?
I did not find any relevant posts regarding the same.

I do not know if I understand correctly your question, tell me if I have to delete the answer.
In Maven, there are the remote repositories and the local repository (under .m2 folder the local one).
In the moment you build a project, the dependencies to build that project are downloaded from the remote repositories and saved into the local repository. So the next time you build a project with that dependency there should be no need to download because there is in your local repository.
There are people who say that the cache and the local repository are the same. But for example, if you use Eclipse and if you go into .m2 folder, you can see a .cache folder. There should be a m2e folder. Here Eclipse save indexes to manage the dependencies.

Related

Maven: Create Clean .m2 from Dirty .m2 to Support Offline Builds

I have a Maven project. One of the repositories is no longer available online.
My local environment has what it needs to build the project offline with -o.
What's a good way to capture only the files this project needs, to provide a copy of the artifacts to others to develop the project in the same offline manner?
I'd like to avoid providing my entire .m2 directory for efficiency.
It would be great if there was a way to save all of the build artifacts for a particular Maven project from a bloated working .m2 to a clean .m2, including only what's necessary to the project, to easily share with others.
Thanks!

simple local repository manager tool for maven

I am using maven to build java projects. I find difficulty in managing artifacts of maven local repository. so, i need a simple tool for managing local repositories of maven.
I seen the apache-archiva and nexus , but those and big tools.
I also searched the internet but i seen only central repository manager tool. I can't find a tool for managing local repository.
I need to know about the artifacts in my local maven reporitory. I don't want to check each folder of my local repository to see what artifacts are installed.
so, please someone tell me about the tools to manage maven local repository.
As far as I know, there are no tools to manage the local repository.
The local repository is more or less just a cache.
Inside a company, you usually set up a Nexus or Artifactory server to manage external and internal artifacts.

Maven build using embedded JAR in project pom

I am working on a Maven project where a build is done through Jenkins, and 1 particular JAR has been removed from corporate repository recently.
So my build is failing as parent pom.xml is referring to a JAR not available in the repo.
But I have the old certified copy downloaded in my local repo, and I want to use the same JAR during build copying in the project folder and want to use the local copy of dependent JAR in pom.xml instead of downloading from corporate repository embedded in the project structure.
How can I do this?
Frankly, this does not sound like a good idea.
While it is possible to reference jars with the <systemPath> entry, it is generally considered bad practise.
By "corporate repository", do you mean a repository of your own company or of some other company? In the first case, you should request that the jar is put back in. In the second case, it would be better not to use the external corporate repository directly, but to set up your own Nexus/Artifactory through which you use (different) external repositories. This Nexus/Artifactory can then host additional artifacts like the one you need (you can e.g. upload them through the UI).

How do I get my local Maven to overwrite an existing artefact that was overwritten in my network repository

I have a Maven repository folder on our network drive, which contains all the artefacts we use.
Everyone in the office uses a standard settings.xml file on their local Maven setup which contains the location of that network drive as a remote repository.
In this way, we keep the network Maven repository folder updated so the local environment on everyone's computers simply downloads from that central repository folder, which avoids re-downloading off the internet for everyone.
We are busy developing a new library, lets say "MyLib 1.0.0". We install it into the central network maven folder repository, and everyone's local Maven projects use that dependency in their project(s). But now, we have not officially released "MyLib 1.0.0", its still a work in progress, so once we make further updates to it, we overwrite the "MyLib 1.0.0" artefact in the central repository.
Problem is, because all our local Maven's have already downloaded the artefact into their local Maven repositories, they wont re-download it. It already exists. I don't want to increase the version of "MyLib" yet because its not an official release, and I also don't want everyone to have to change their dependency version in their pom.xml files. I just want to replace the "MyLib 1.0.0" file and have everyone's local Maven's download and overwrite their local copy automatically. (At the moment everyone has to be told to go and remove the artefact from their local Maven repository manually, as which point it will re-download the latest copy of "MyLib 1.0.0")
What is best practice for the above, or how can I go about achieving this?
Based on your description there are comming two things into my mind.
First:
Stop using a network drive. Better start using a repository manager.
Apart from that a network drive is dammed slow.
Second:
In Maven a release is immutable which means if you have version 1.0 and deploy to your repository it will never being changed anymore. If you need to make a change on that you have to use a different version for example 1.0.1 etc.
You should start using SNAPSHOT's instead of releases if you are developing which is exactly causing the problem:
At the moment everyone has to be told to go and remove the artefact
from their local Maven repository manually, as which point it will
re-download the latest copy of "MyLib 1.0.0"
Which shows you are working against the concepts of Maven.
And third. It sounds like you don't use a continious integration for your builds.

How to change updatePolicy for my local Maven repository?

I know how to do it for an external repository but not for my local repository, since I don't have a <repository> for my local repository in my settings.xml.
I use snapshot versions for my sub-projects, so when I re-build the parent project I want maven to get all the sub-projects snapshot versions from my local repository not only once a day (which seems to be what happens by default) but always.
If I'm understanding your comment, I think #FrVaBe may have the correct answer. When you change code for a child project on your development machine, it's up to you to rebuild the snapshot and get it into your local artifact repo (via mvn install) so it's available for the parent project to use.
If, however, you want your parent project build to pull in changes made by your teammates and published to the corporate remote repository more often than once per day, read on.
Here is a summary of how Maven central (and kin), remote repositories (e.g a company instance of Nexus or Artifactory) and your local repository work together. If you always want the latest version of snapshots to download on every build, go into your settings.xml file, find <snapshot> repository containing the snapshot you want, and change the <updatePolicy> value to "always". Personally I rarely do this, I simply add the '-U' option to my mvn command line when I want to ensure I have the latest version of a snapshot from my remote repo.
There is no update policy for the local repository!
The local repository is just a bunch of files. When you install to your local repository your local projects already reference the artifacts directly. There is no update that needs to be performed except that maybe your IDE needs to be refreshed to pickup the newer files.
In this manner you can build local snapshots all day long with no versioning headaches, no updates required and no old artifacts left hanging around afterwards. Nice and clean but not so obvious if you're new to Maven and still getting to grips with all these repositories and their fancy update mechanisms.
I think you missunderstood something. Maven will always take the latest/newest SNAPSHOT from your local respository. But in your project setup (Project Inheritance) you need to build the sub projects on their own if you changed something.
An automatical build of the sub project only happens on a Project Aggregation layout.
The difference is explained in the Project Inheritance vs Project Aggregation section of the documentation.

Resources