Maven repositories are physical directories that contain packaged JAR files along with extra metadata about these jar files. This metadata is in the form of POM files that have jar file project information, including what other external dependencies this JAR file has. These other external dependencies are downloaded transitively into your project and become part of the effective pom for the project.
1. Local Repository
Maven local repository resides in the developer’s machine. Whenever you run Maven goals that require these dependencies, maven will download the dependencies from remote servers and store them on the developer’s machine.
By default, Maven creates the local repository inside the user’s home directory i.e. C:/Users/superdev/.m2
directory. You can change the location of the local repository in setting.xml file using localRepository
tag.
<settings>
<localRepository>C:\M2</localRepository>
</settings>
Having stored the dependencies on the local machine has two main benefits.
- First, multiple projects can access the same artifact so it reduces the storage need.
- Second, as dependency is downloaded only once, it reduces network usage as well.
2. Central Repository
Maven central repository is located at https://repo.maven.apache.org/maven2/. Whenever you run a build job, maven first tries to find dependency from the local repository. If it is not there, then, by default, maven will trigger the download from this central repository location.
To override this default location, you can make changes to your settings.xml
file to use one or more mirrors.
You do not need to make any special configuration to allow access to the central repository, except network proxy settings if you are behind any firewall.
3. Remote Repository
Apart from the central repository, you may have needed artifacts deployed in other remote locations. For example, in your corporate office, there may be projects or modules specific to the organization only. In this case, the organization can create a remote repository and deploy the private artifacts. This remote repository will be accessible only inside the organization.
These Maven remote repository work exactly the same way as Maven’s central repository. Whenever an artifact is needed from these repositories, it is first downloaded to the developer’s local repository and then it is used.
You can configure a remote repository in the POM file or super POM file in the remote repository itself.
<repositories>
<repository>
<id>org.source.repo</id>
<url>https://maven.orgName.com/maven2/</url>
</repository>
</repositories>
Drop me your questions in the comments section.
Happy Learning !!
Hi Lokesh
Is there any way when we build the maven the same generated jar file move to jfrog repository after install into our local machine, I need to push to remote as well.
Main pom.xml will your tag that is helpful or someother tag we need to use
what are configuration we need to do
I am getting below error while building an application. Can you please tell me how to solve this.
settings.xml
is corrupt. Please fix it.This is out of date as of January 15, 2020. The Central repository only supports HTTPS as per https://support.sonatype.com/hc/en-us/articles/360041287334
Where to change the endpoint from http:// to https://
Did you got any response or answer on this “Where to change the endpoint from http:// to https:// ? “
The repository URLs in settings.xml.
Hi Lokesh,
In my Project are in settings.xml as well as in pom.xml .What is the difference..do these configuration work simultaneously and download artifacts. or settings.xml override repository configuration in
pom.xml .Please guide on this.
Hi Lokesh,
Is there a way to access the repository path in pom.xml. I mean is it available through some default placeholder.
The problem is I need to access pom.xml of one project through another pom.
Hi Lokesh,
I am new to Maven ,In Pom.xml somtimes we for a dependency we put version as $abc and sometimes we put it as 4.2.6 what is the difference between both these .
My understanding is if some dependency is not available in configured repository then we put the dependency manually in mvn repository . so ,we put version as 4.2.6 in that case . Please guide me on this.
${a.b.c} is property placeholder and it’s value is resolved from declared properties in
pom.xml
file.Otherwise, directly the version number is mentioned inline e.g. 4.2.6.
Thanks Lokesh…
when I build then I got this error so kindly tell me what I will do……………………… maven is not looking to the local repo
See if it works: https://stackoverflow.com/questions/19180696/maven-not-using-local-repository
Hi!
Is it possible to tell Maven to use remote repo for specific packages only (using mask, for example: ‘com.example.*’) but other packages download from central repo?
How to achieve this?
Thanks in advance!
How we can upload jars to remote repositories??
Including jars what all meta data files we need to upload??
How we write metadata file??