Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - Is it possible to specify mirror in pom.xml?

Tags:

maven-2

maven

Is it possible to specify mirror in pom.xml ? For example I am want to make one my own repo like central repo. And I want disable requests to the central repo and make all requests to my own repo. Is it possible to disable default central repo in Maven?

like image 605
Arthur Avatar asked Aug 22 '12 11:08

Arthur


People also ask

Does POM xml override settings xml?

It's important to note that values from an active profile in settings. xml will override any equivalent profile values in a pom. xml or profiles.

What does mirror do in Maven settings xml?

You can force Maven to use a single repository by having it mirror all repository requests. The repository must contain all of the desired artifacts, or be able to proxy the requests to other repositories.

What is mirror tag in Maven?

The mirror to http://a.com:8081 will be used when Maven will try to fetch a dependency from one of the repository that it mirrors.


2 Answers

In the pom it's not possible to define mirror entries furthermore it would be bad practice if definition of mirrors were possible (which is not the case). Similar for repositories definition in pom's (which are possible, but considered bad practice).

Best solution for such kind of thing is to install a repository manager which acts like a "own central repository."

like image 149
khmarbaise Avatar answered Sep 22 '22 11:09

khmarbaise


Mirror can't be in the pom.xml. but it can be put add to your project's files.

When using maven 3.3.1+, you can use the core extension project-settings-extension to load the project settings, and put project specific mirrors into ${basedir}/.mvn/settings.xml in your project.

in ${basedir}/.mvn/extensions.xml

    <extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">       <extension>         <groupId>com.github.gzm55.maven</groupId>         <artifactId>project-settings-extension</artifactId>         <version>0.1.1</version>       </extension>     </extensions> 

in ${basedir}/.mvn/settings.xml

<settings>   <mirrors>     <mirror>       <id>id</id>       <url>https://url-for-this-project/</url>       <mirrorOf>central</mirrorOf>     </mirror>   </mirrors> </settings> 
like image 36
James Z.M. Gao Avatar answered Sep 18 '22 11:09

James Z.M. Gao