开发者

maven repository mirrors

Normally, I have the following mirror configured in my Maven settings.xml

<mirror>
  <id>internal-repository</id>
  <url>http://build.idaho.local/wtp_repository</url>
  <mirrorOf>*</mirrorOf>
</mirror>

My understanding is that this mirror prevents Maven from downloading dependencies from the internet, i.e. it will only look for them in this internal repository.

However, whenever I want to add a dependency that isn't in this internal repository, I have to comment out the text above and add the following to the project's pom.xml

<repository>
  <id>internal-repository</id>
  <url>http://build.idaho.local/wtp_repository</url>
</repository>

When I make these changes Maven will check for dependencies in the local repo, and if not found, download them from the internet to the local repo. Once I have the dependencies I need, I then change my configuration back.

Is there a way to get the behaviour I want - always check the internal repo, then the public (Internet) repos - without 开发者_StackOverflow中文版having to add the <repository> to every project's pom.xml?

Ideally I would like to specify this repository once in settings.xml, but it seems that you can only configure mirrors there.


You could try to configure maven to use the mirror only for the central repository or to exclude the repository identified by some id.

<mirror>
    <id>internal-mirror</id>
    <url>http://build.idaho.local/wtp_repository</url>
   <mirrorOf>central</mirrorOf>
</mirror>

Or

<mirror>
    <id>internal-mirror</id>
    <url>http://build.idaho.local/wtp_repository</url>
   <mirrorOf>*,!internal-repository</mirrorOf>
</mirror>

The examples were adapted from maven settings and guide to mirror settings.


This question is quite old, but anyway:

Put a <profile> in your settings.xml that specifies your internal repository using the <repository> element

...
    <profile>
        <id>devel-repos</id>

        <repositories>
            <repository>
                <id>repo-release</id>
                <url>http://repohost:repoport/path/to/release/repo</url>
            </repository>
            <repository>
                <id>repo-snapshot</id>
                <url>http://repohost:repoport/path/to/snapshot/repo</url>
            </repository>
        </repositories>
    </profile>
...

Then set the above profile as <activeProfile>. This will activate the profile for every maven invocation.

...
<activeProfiles>
    <activeProfile>devel-repos</activeProfile>
</activeProfiles>
...

This does not avoid multiple repository definitions, but it gives you the most important thing: everything is centralized in settings.xml and your pom.xmls are clean (and portable).


It looks like you may not have configured or using the mirror correctly.

Ideally, what you specify as the mirror should be a repository manager, which should transparently download the requested dependency from various repositories in the internet and cache it, thereby allowing subsequent downloads to happen from the mirror.


Add the repository section to the super pom. And let all the projects extend from the super pom.

So every other project pom will have a parent section to extend from the super pom like this.

<parent>
    <groupId>com.ddd.ddd.ddd</groupId>
    <artifactId>ddd-ddd-parent</artifactId>
    <version>1.1.1-SNAPSHOT</version>
    <relativePath>./config/superpom/pom.xml</relativePath>
</parent>

This way you can have the repository section only in one pom file, thats your super pom. You can also add any dependencies that are common to all the projects in here, like junit, log4j and stuff like that.

In your settings.xml file. You can add this to configure your local repository.

<localRepository>C:/myBox/maven.repo</localRepository>


Removing mirror settings from settings.xml and put following code worked for me.

<profiles>
    <profile>
        <id>profile-1</id>
        <repositories>
            <repository>
                <id>internal-repository-1</id>
                <url>http://build.idaho.local/wtp_repository</url>
            </repository>
        </repositories>
    </profile>
</profiles>
<activeProfiles>
    <activeProfile>profile-1</activeProfile>
</activeProfiles>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜