How to add remote repository in Maven

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

For the pom.xml of the project, you would need to define the dependency like:

<repositories>  <repository>    <id>Internal company repository</id>    <url>http://mvnrepo.company.com/</url>  </repository></repositories>(...)<dependencies>  <dependency>    <groupId>com.example</groupId>    <artifactId>interviewbubble</artifactId>    <version>1.0</version>  </dependency></dependencies>

using below mentioned POM.xml, Maven will download dependency (not available in central repository) from Remote Repositories mentioned in the same pom.xml.

<project xmlns = "http://maven.apache.org/POM/4.0.0"   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0   http://maven.apache.org/xsd/maven-4.0.0.xsd">   <modelVersion>4.0.0</modelVersion>   <groupId>com.companyname.projectgroup</groupId>   <artifactId>project</artifactId>   <version>1.0</version>   <dependencies>      <dependency>         <groupId>com.example</groupId>         <artifactId>interviewbubble</artifactId>         <version>1.0</version>      </dependency>   <dependencies>   <repositories>      <repository>         <id>Internal company repository</id>         <url>http://mvnrepo.company.com/</url>      </repository>   </repositories></project>


Maven Dependency Search Sequence

When we execute Maven build commands, Maven starts looking for dependency libraries in the following sequence:

Step 1 − Search dependency in the local repository, if not found, move to step 2 else perform the further processing.

Step 2 − Search dependency in the central repository, if not found and if remote repository/repositories is/are mentioned then go to step 4 else it is downloaded to local repository for future reference.

Step 3 − If a remote repository has not been mentioned, Maven simply stops the processing and throws an error

([ERROR] Failed to execute goal on project Test: Could not resolve dependencies for project Test:Test:jar:1.0.0).

Step 4 − Search dependency in remote repository or repositories, if found then it is downloaded to local repository for future reference. Otherwise, Maven stops processing and throws an error

([ERROR] Failed to execute goal on project Test: Could not resolve dependencies for project Test:Test:jar:1.0.0).