Nathan Reese
Nathan Reese

Reputation: 2734

How do you configure maven to ignore repositories specified in POM files?

I have a project on a company intranet (read - no outside internet access). I have a server running Artifactory with all required maven artifacts. I have a settings.xml file pointing maven to the running Artifactory server. Everything is happy and maven can download dependencies until an artifact specifying a repository in the POM file (in my case org/eclipse/jetty/jetty-project/7.5.4.v20111024/jetty-project-7.5.4.v20111024.pom). Then maven attempts to load the remaining dependencies from the repo specified in the POM file instead of from Artifactory. This breaks the build. How do you configure maven to ignore repositories specified in POM files?

Thanks,

Nathan

Upvotes: 15

Views: 13948

Answers (2)

Joe
Joe

Reputation: 31110

As a workaround, define another repository in your settings.xml with the same ID (is it oss.sonatype.org, defined in jetty-parent:19, that's the problem?) and point it at your repo. Maven will use that definition in favour of the one in the pom.

There's an open issue filed against Maven (MNG-3056) to allow this to be configured so only your repo would be used; in general, if you have a local repository, that would be the behaviour you would want.

Upvotes: 9

Andreas Panagiotidis
Andreas Panagiotidis

Reputation: 3032

That's a great answer Joe. Thank you. I was looking for it for quite some time.

I just quote an example, in which I had the same problem as Nathan.

I use a Maven enterprise repository (Nexus or Artifactory) and I am behind a proxy, that means that I cannot download directly (and do not want to) from any other repositories than mine.
Jasper reports net.sf.jasperreports:jasperreports:6.2.0 defines in its pom a couple of repositories.

<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.2.0</version>
...
<repositories>
    <repository>
        <id>jasperreports</id>
        <url>http://jasperreports.sourceforge.net/maven2</url>
    </repository>
    <repository>
        <id>jaspersoft-third-party</id>
        <url>http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/</url>
    </repository>
</repositories>

This causes the following exception:

C:\my-project>mvn verify
[INFO] Scanning for projects...

[INFO] Building my-project 1.0.0-SNAPSHOT
[INFO] 
Downloading: http://mynexus/nexus/content/groups/ch-public/com/lowagie/itext/2.1.7.js4/itext-2.1.7.js4.pom
Downloading: http://jasperreports.sourceforge.net/maven2/com/lowagie/itext/2.1.7.js4/itext-2.1.7.js4.pom
Downloading: http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/com/lowagie/itext/2.1.7.js4/itext-2.1.7.js4.pom
[INFO] BUILD FAILURE
[INFO] Could not resolve dependencies for project ... :
Failed to collect dependencies at net.sf.jasperreports:jasperreports:jar:6.2.0 -> 
com.lowagie:itext:jar:2.1.7.js4: Failed to read artifact descriptor for com.lowagie:itext:jar:2.1.7.js4: 
Could not transfer artifact com.lowagie:itext:pom:2.1.7.js4 
from/to jasperreports (http://jasperreports.sourceforge.net/maven2): 
Connect to jasperreports.sourceforge.net:80 [jasperreports.sourceforge.net/216.34.181.96] 
failed: Connection timed out: 

The solution as described by Joe is: In global settings.xml (C:/maven-installation/conf/settings.xml) or private settings.xml (~/.m2/settings.xml) add the following profile:

<profiles>
    <profile>
        <id>ignore-repositories</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <repositories>
            <repository>
                <id>jasperreports</id>
                <url>http://mynexus/nexus/content/groups/ch-public/
                </url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>jaspersoft-third-party</id>
                <url>http://mynexus/nexus/content/groups/ch-public/
                </url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
        </repositories>
    </profile>
</profiles>

Important: the repository id in the profiles (jasperreports , jaspersoft-third-party) matches exactly the id of the repository used in pom.xml - in this case the pom.xml of net.sf.jasperreports:jasperreports:6.2.0

Do not forget to add the "external" repositories to the "proxy" list of your Maven Enterprise Repository

Upvotes: 3

Related Questions