Maven Setting Mirror

Maven Mirror specify from where dependencies should be downloaded. There is already repository tag is available but maven mirror used in specific condition. Let's see that.
  1. Geographically closer mirror to get dependencies
  2. You want to represent repository which have better control of dependencies
  3. Need to provide local cache to repository manager
  4. In the organisation, to avoid external traffic we can use mirror.
Let's see the working of mirror.

The scenario is like, we have two repository first, Maven Central and second, Custom
  1. We have declared dependencies to an  artifact.
  2. Maven will look into Custom repository.
  3. Dependencies is not found into the Custom repository. 
  4. Maven will go to central repository. Maven will notice that mirror was configured for that repository. Maven will not go to central but it will go to mirror URL.
Following way we can declare, Mirror in settings.xml

  1. <settings>
  2. ...
  3. <mirrors>
  4. <mirror>
  5. <id>mirror</id>
  6. <name>Mirror Repository</name>
  7. <url>https://mirror.repo.com/maven2</url>
  8. <mirrorOf>central</mirrorOf>
  9. </mirror>
  10. </mirrors>
  11. ...
  12. </settings>


Here, <mirrorOf> has significance to specify usage of mirror. for example, we want to specify single mirror for all the respository manager or all.


Conclusion:

We can use mirror to provide local cache with repository manager. It helpful in case dependencies can not be download from central repository. We can use mirror to avoid traffic outside organisation network.

Comments

Popular posts from this blog

Spring Session

Hibernate Version 5.0