bramdc
bramdc

Reputation: 652

Disable maven settings mirror via local pom

In my maven settings.xml is following snippet:

<mirrors>
    <mirror>
        <!--This sends everything to our company mirror -->
        <id>nexus</id>
        <mirrorOf>*</mirrorOf>
        <url>[company-mirror]</url>
    </mirror>
</mirrors>

This sends everything to our company mirror and if it can't resolve it, it we will get it from the maven repository.

Now we also receive bug fixes from a vendor from one of our technologies via their maven nexus. Problem is our company mirror doesn't automatically query this nexus, I can easily provide following mirror edit in the settings.xml:

<mirrors>
  <mirror>
    <id>[vendor-id]</id>
    <mirrorOf>[vendor-mirror]</mirrorOf>
    <url>[vendor-url]</url>
 </mirror>
 <mirror>[company-mirror-settings]</mirror>
</mirrors>

And then it will query fine but we can not do this for our company maintained build server which just queries the company mirror.

Is there a way to do it in our local pom.xml/project without touching any external settings?

I have tried following in our pom.xml but it didn't work:

<project>
...
<repositories>
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>[vendor-id]</id>
        <name>[vendor-name]</name>
        <url>[vendor-url]</url>
    </repository>
</repositories>
...
</project>

running mvn clean install gets following error:

[ERROR] Failed to execute goal on project <project-name>: Could not resolve dependencies for project <project-name>:jar:1.2.0-SNAPSHOT: Coul
d not find artifact <vendor-dependency> in <company-mirror>

Upvotes: 5

Views: 2148

Answers (1)

KevinLH
KevinLH

Reputation: 338

The mirrors definition in settings.xml allow for overloading of the default central repository as well as any repository defined in the POMs. As a consequence, if your build server uses a settings file with your company-managed repository defined as <mirrorOf>*</mirrorOf>, it will use it for every single POM-defined repository, and basically ignore these definitions.

So either the settings.xml used by the build server should be modified so that not all repository are mirrored, or the company-managed repository should be configured to mirror the repository of the vendor.

Maven documentation: Using Mirrors for Repositories

Upvotes: 5

Related Questions