Maven – Local, Remote and Central Repositories

Maven repositories are physical directories which contain packaged JAR files along with extra meta data about these jar files. This meta data is in form of POM files which 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 effective pom for the project.

Table of Contents

Local repository
Central repository
Remote repository

Local repository

Maven local repository reside in the developer’s machine. Whenever you run maven goals which require these dependencies, maven will download the dependencies from remote servers and store them into developer’s machine.

By default, Maven create the local repository inside user 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 into local machine has two main benefits. First, multiple projects can access same artifact so it reduces the storage need. Second, as dependency is downloaded only once, it reduces the network usage as well.

Central repository

Maven central repository is located at http://repo.maven.apache.org/maven2/. Whenever you run build job, maven first try to find dependency from local repository. If it is not there, then, by default, maven will trigger the download from this central repository location.

Maven Central Repository
Maven Central Repository

To override this default location, you can 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 the central repository, except network proxy settings if you are behind any firewall.

Remote repository

Apart from central repository, you may have needed artifacts deployed on other remote locations. For example, in your corporate office there may be projects or modules specific to organization only. In this cases, organization can create remote repository and deploy these private artifacts. This remote repository will be accessible only inside organization.

These maven remote repository work exactly same way as maven’s central repository. Whenever an artifact is needed from these repositories, it is first downloaded to developer’s local repository and then it is used.

You can configure a remote repository in the POM file or super POM file in remote repository itself.

<repositories>
   <repository>
       <id>org.source.repo</id>
       <url>http://maven.orgName.com/maven2/</url>
   </repository>
</repositories>

Drop me your questions in comments section.

Happy Learning !!

Ref: Introduction to Repositories

Was this post helpful?

Join 7000+ Fellow Programmers

Subscribe to get new post notifications, industry updates, best practices, and much more. Directly into your inbox, for free.

14 thoughts on “Maven – Local, Remote and Central Repositories”

  1. 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

    Reply
  2. I am getting below error while building an application. Can you please tell me how to solve this.

    [WARNING] Some problems were encountered while building the effective settings
    [WARNING] Unrecognised tag: 'build' (position: START_TAG seen ...\r\n  ... @252:10) 
     @ C:\maven-3.0.3\bin\..\conf\settings.xml, line 252, column 10
    [WARNING]
    [INFO] Scanning for projects...
    Downloading: http://repository.codehaus.org/org/codehaus/mojo/
    jboss-packaging-maven-plugin/maven-metadata.xml
    [WARNING] Could not transfer metadata org.codehaus.mojo:
    jboss-packaging-maven-plugin/maven-metadata.xml 
    from/to codehaus (http://repository.codehaus.org): 
    
    Reply
  3. 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.

    Reply
  4. 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.

    Reply
  5. 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.

    Reply
    • ${a.b.c} is property placeholder and it’s value is resolved from declared properties in pom.xml file.

      &lt;properties&gt;
          &lt;sb.web.version&gt;2.1.8&lt;/sb.web.version&gt;
      &lt;/properties&gt;
      
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;version&gt;${sb.web.version}&lt;/version&gt;
      &lt;/dependency&gt;
      

      Otherwise, directly the version number is mentioned inline e.g. 4.2.6.

      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;version&gt;2.1.8&lt;/version&gt;
      &lt;/dependency&gt;
      
      Reply
  6. when I build then I got this error so kindly tell me what I will do……………………… maven is not looking to the local repo

    [INFO] galaxy-device-management 1.0 ....................... SUCCESS [  1.014 s]
    [INFO] galaxy-device-management-client .................... SUCCESS [02:01 min]
    [INFO] galaxy-device-management-server .................... FAILURE [  8.712 s]
    [INFO] galaxy-device-management-boot 1.0 .................. SKIPPED
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 02:12 min
    [INFO] Finished at: 2019-07-05T11:28:08+05:30
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal on project galaxy-device-management-server: Could not resolve dependencies for project com.els.galaxy:galaxy-device-management-server:jar:1.0: Failed to collect dependencies at com.els.galaxy:galaxy-device-certificate:jar:1.0-SNAPSHOT: Failed to read artifact descriptor for com.els.galaxy:galaxy-device-certificate:jar:1.0-SNAPSHOT: Could not find artifact com.els.galaxy:parent:pom:1.0-SNAPSHOT in nexus (http://10.98.11.18:8888/nexus/repository/maven-public) -> [Help 1]
    [ERROR]
    
    Reply
  7. 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!

    Reply
  8. How we can upload jars to remote repositories??
    Including jars what all meta data files we need to upload??
    How we write metadata file??

    Reply

Leave a Comment

HowToDoInJava

A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.