17

I have the following in .m2, disabling the default remote repo:

<?xml version="1.0" encoding="UTF-8"?> 
<settings>
<mirrors>
  <mirror>
    <id>my.mirror</id>
    <name>My Mirror</name>
    <url>https://repo.maven.apache.org/alwaysfail</url>
    <mirrorOf>*</mirrorOf>
  </mirror>
</mirrors>

Now I added this in my project pom.xml

<repositories>
    <repository>
        <id>myproject.repo</id>
        <url>https://repo.maven.apache.org/maven2</url>
    </repository>
</repositories>

But it does not pick up my project specific remote repo and start downloading, what am I doing wrong?

powder366
  • 4,351
  • 7
  • 47
  • 79
  • You seemed to misunderstand the meaning of mirrorOf. Your `settings.xml` configuration mean to redirect any configuration your are making in your pom to redirect to the one you have made into the one you have defined in your mirrorOf configuration. I don't understand why you like to prevent using Maven central ? – khmarbaise Feb 25 '17 at 11:50
  • I just disabled the one in .m2 to test how I can configure a project specific repo i.e. the one in pom.xml (which in my test case is the Maven central). We can't access the Internet and we have our own company internal repository. I like to set up different project specific internal repos. – powder366 Feb 25 '17 at 12:02
  • Configure only the internal repository manager in settings.xml which means imply use the url of the internal repository in the url and don't put repositories into pom files... – khmarbaise Feb 25 '17 at 16:00

1 Answers1

25

setting.xml allows you to override definitions in pom.xml, not the other way round. If you want to not use the overriding in settings.xml in a particular build, you could prepare another settings file and call it explicitly:

$ mvn install -s /path/to/no-repo-override.xml
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • If I remove my settings.xml and define it only in my pom.xml described above and then change the url to a wrong link it still downloads! I only want my pom.xml to be the url to define where I get my dependencies. How can I do that? So if the pom.xml url is wrong it should fail. – powder366 Feb 25 '17 at 12:15
  • Addition to Mureinik's answer, if you are using intellij to sync maven projects. You can open the maven build toolbar, click on settings and specify the new settings.xml file in the "User setting file" option. This will set the new setting file only for that project. – Vipul Behl Aug 19 '23 at 20:19