Repositories in Maven

Maven searches for artifacts in 3 repositories.
  • Local ( userHomeDirectory/.m2/repository )
  • Central (https://repo1.maven.org/maven2/)
  • Remote repositories (if any specified)
When you first time build your project, maven downloads all required artifacts from central and remote repositories and stores them in local repository. So in subsequent builds, maven uses artifacts stored in local repository. From where maven gets that artifact? Well- the answer is simple. Maven stores all popular artifacts at central location (also called as maven central repository) The url is https://repo1.maven.org/maven2/ and it is maintained by https://central.sonatype.org/ You can also search for artifacts at https://search.maven.org/ So what if certain artifact is not there on central repository? In that scenario, maven will throw error saying

could not find the artifact.
[ERROR] Failed to execute goal on project xyz: Could not resolve 
dependencies for project xyz:jar:1.0-SNAPSHOT: Could not find artifact 
org.seleniumhq.selenium:selenium-java1:jar:2.52.0 in repository1
But if that artifact is available in different repository, you can add that repository in POM file using repository tag so that maven will search there. Please note that you can also add repositories in settings.xml file
 
<repositories>
<repository>
<id>org.softpost</id>
<url>https://softpost.org/repositories/public/</url>
</repository>
<repository>
<id>xyz.lib</id>
<url>https://download.xyz/lib</url>
</repository>
</repositories>

Complex problems, Simple Solutions