50

The development machine cannot access the internet, and take about 60s to timeout. When I try to build, I see

Downloading: http://repo.maven.apache.org/maven2/com/google/gsa-connector/2.8.0/gsa-connector-2.8.0.pom

However, I have the following in my POM:

    <repository>
      <id>bb-nexus</id>
      <url>http://repo.dev.bloomberg.com/content/groups/public</url>
      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
    </repository>
    <repository>
      <id>nexus-3rdparty</id>
      <url>http://repo.dev.bloomberg.com/content/repositories/thirdparty/</url>
      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
    </repository>

It always tries to go to repo.maven first. I even tried to add to D:\.m2\settings.xml

<settings>
  <mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://repo.dev.bloomberg.com/content/groups/public</url>
    </mirror>
  </mirrors>

based on http://maven.apache.org/guides/mini/guide-mirror-settings.html yet it continues to try repo.maven first. I'm using Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)

I can't use -o because it still needs to access the local repo.dev.


Here is with 'effective-settings':

D:\Users\chloe\Projects\team\confluence-plugin>mvn help:effective-settings
[INFO] Scanning for projects...
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/maven-metadata.xml
[WARNING] Could not transfer metadata org.apache.maven.plugins:maven-install-plugin/maven-metadata.xml from/to central (
http://repo.maven.apache.org/maven2): Connection to http://repo.maven.apache.org refused
...
[INFO]
[INFO] --- maven-help-plugin:2.1.1:effective-settings (default-cli) @ bb-confluence-plugin ---
[INFO]
Effective user-specific configuration settings:

<?xml version="1.0" encoding="UTF-8"?>
...
<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLoca
tion="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <localRepository xmlns="http://maven.apache.org/SETTINGS/1.1.0">d:\.m2\repository</localRepository>
  <pluginGroups xmlns="http://maven.apache.org/SETTINGS/1.1.0">
    <pluginGroup>org.apache.maven.plugins</pluginGroup>
    <pluginGroup>org.codehaus.mojo</pluginGroup>
  </pluginGroups>
</settings>

[INFO] ------------------------------------------------------------------------
Chloe
  • 25,162
  • 40
  • 190
  • 357
  • http://stackoverflow.com/questions/3637277/how-to-prevent-maven-from-checking-foreign-repositories ? – leoluk Oct 08 '12 at 21:14
  • @leoluk We aren't using SNAPSHOTS, and we don't even have repo.maven.org listed as a repository, so we can't turn that option off. I don't mind if it checks our internal repo for snapshots. – Chloe Oct 08 '12 at 21:21
  • 3
    does `mvn help:effective-settings` confirm that the mirror settings are being applied? – Brett Porter Oct 09 '12 at 03:21
  • @BrettPorter Ok I updated with output from effective-settings. I updated settings.xml and ran mvn. No, it did not appear to take. – Chloe Oct 09 '12 at 17:12
  • Maybe wrong directory for your settings.xml file? – rogerdpack Mar 08 '21 at 19:01

3 Answers3

54

All pom files inherit from the maven super POM http://maven.apache.org/ref/3.0.4/maven-model-builder/super-pom.html which contains this entry:

<repositories>
    <repository>
        <id>central</id>
        <name>Central Repository</name>
        <url>http://repo.maven.apache.org/maven2</url>
        <layout>default</layout>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

Try setting this in your pom (with <id>central</id>):

<repositories>
    <repository>
        <id>central</id>
        <url>http://repo.dev.bloomberg.com/content/groups/public</url>
        <releases>
            <enabled>false</enabled>
        </releases>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>central</id>
        <url>http://repo.dev.bloomberg.com/content/groups/public</url>
        <releases>
            <enabled>false</enabled>
        </releases>
    </pluginRepository>
</pluginRepositories>
Nadjib Mami
  • 5,736
  • 9
  • 37
  • 49
Devin Jones
  • 556
  • 5
  • 2
  • 1
    Also, you may need to add nexus to the list of servers in your settings.xml `nexus` – Devin Jones Oct 09 '12 at 21:28
  • 1
    That didn't work. It gave this error: `[ERROR] 'repositories.repository[central].url' is missing. @ com.bloomberg:bb-confluence:1.0, D:\Users\chloe\Projects\team\pom.xml, line 174, column 15 [ERROR] Invalid artifact repository: URL missing for repository central -> [Help 2]`. I added the URL to my repo, but it still gave this error: `[WARNING] Could not transfer metadata org.apache.maven.plugins:maven-install-plugin/maven-metadata.xml from/to central (http://repo.maven.apache.org/maven2): Connection to http://repo.maven.apache.org refused`. – Chloe Oct 11 '12 at 17:08
  • 2
    Ok got it! I had to add ` central`. – Chloe Oct 11 '12 at 17:23
  • 1
    beware: effective pom depends on both ~/.m2/settings.xml and $M2_HOME/conf/settings.xml (but not only) – Francois Aug 12 '14 at 12:25
  • I read http://tomcat.apache.org/maven-plugin-trunk/snapshot-test.html that maven 2.x relies on an "apache.snapshots" repository and pluginRepository. – eel ghEEz Feb 08 '17 at 04:09
  • Yeah I don't know why it worked but it worked. so thank you! – Nicholas DiPiazza Oct 02 '17 at 02:14
  • thx worked for me but I had to remove false – jumptiger13 Feb 14 '20 at 18:11
31

Overriding the central repository

How it works:

Most organizations will need to set up one or more shared repositories, since not everyone can deploy, or simply download from the central Maven repository.To publish releases for use across different environments within their network, organization's will typically want to set up what is referred to as an internal repository.

When using this repositories for your projects, there are two choices: use it as a mirror, or have it override the central repository. You would use it as a mirror if it is intended to be a copy of the central repository exclusively, and if it's acceptable to have developers configure this in their settings. Or like in this case that you want to prevent access to the central repository for greater control, to configure the repository from the project level instead of in each user's settings, or to include your own artifacts in the same repository, you should override the central repository.

Also, Is very important to have in mind, at this point, the resolution process conducted by the maven dependencies, which have two main blocks settings for repositories:

  1. related to the decencies will be listed within us ;
  2. related to plugins that will be added within the nodes or used during the life cycle.

The Solution:

As an object oriented framework Maven has all POMs have an implicit parent the Super POM. Under its definitions lay down both dependencies and plugins first resolver repositories configurations:

<repositories>
    <repository>
      <id>central</id>
      <name>Maven Repository Switchboard</name>
      <layout>default</layout>
      <url>http://repo1.maven.org/maven2</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <name>Maven Plugin Repository</name>
      <url>http://repo1.maven.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
    </pluginRepository>
  </pluginRepositories> 

To override the central repository with your internal repository, you must define a repository in a settings file and/or POM that uses the identifier central (<id>central</id>). Usually, this must be defined as both a regular repository and a plugin repository to ensure all access is consistent. For example:

<repositories>
    <repository>
      <id>central</id>
      <name>Maven Repository Switchboard</name>
      <layout>default</layout>
      <url>http://repo.dev.bloomberg.com/content/groups/public</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <name>Maven Plugin Repository</name>
      <url>http://repo.dev.bloomberg.com/content/groups/public</url>
      <layout>default</layout>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
    </pluginRepository>
  </pluginRepositories> 

Related link: Coderwall - Stopping maven from trying to access its Central Repository

Nadjib Mami
  • 5,736
  • 9
  • 37
  • 49
helmedeiros
  • 487
  • 6
  • 4
  • 2
    This is for maven 2. For Maven 3, you just need to provide a `` property, as described in https://maven.apache.org/settings.html#Mirrors – Todd Owen Sep 13 '17 at 00:58
  • 1
    The `` way is apparently "more" effective since sometimes pom files can specify their own repositorys...so it avoids that as well...https://stackoverflow.com/a/25666784/32453 – rogerdpack Mar 08 '21 at 19:03
0

Try setting the following in the reporting/plugins block

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>2.9</version>
        <configuration>
            <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
        </configuration>
    </plugin>
Sreesankar
  • 299
  • 2
  • 6