Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
756 views
in Technique[技术] by (71.8m points)

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 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...