mavenmaven-repository

Force maven to use a specific repository for extensions


I have a maven extension added to my .mvn/extensions.xml and when I try to execute maven it tries to download it from maven central. We recently switched to internal repos and while my artifacts and plugins are downloaded from the repositories defined in the pom and not from maven central, the extensions are still being downloaded from maven central. Is there any way to instruct maven to use alternative repos when downloading extensions?

My .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>fr.brouillard.oss</groupId>
    <artifactId>jgitver-maven-plugin</artifactId>
    <version>1.5.1</version>
  </extension>
</extensions>

Maven version: 3.8.6


Solution

  • The way I solved it was to add to my settings.xml. Adding them to pom.xml doesn't work (I guess maven needs to have extensions resolved prior to loading pom.xml) and I didn't find other ways of doing it. A workaround I also found was to comment out extensions and use dependency:get to manually download dependencies but it has it's problems too.

    What I added to the ~/.m2/settings.xml

    <mirrors>
        <mirror>
          <id>local-maven-central</id>
          <name>Maven Central</name>
          <url>URL OF OUR LOCAL central MIRROR</url>
          <mirrorOf>central</mirrorOf>
        </mirror>
        <mirror>
          <id>local-maven-apache</id>
          <name>Maven Apache Mirror</name>
          <url>URL OF OUR LOCAL apache MIRROR</url>
          <mirrorOf>apache</mirrorOf>
        </mirror>
    </mirrors>