maven pom中的repository節點配置沒有起作用


問題描述

昨天晚上想用spring boot快速搭建一個web開發的項目,就打開spring boot的doc,按照說明開始嘗試。沒想到出師未捷身先死,第一步就掛了。
以下是spring boot的配置文件,參考:http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#getting-started-first-application

xml


4.0.0

<groupId>com.example</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.2.BUILD-SNAPSHOT</version>
</parent>

<!-- Additional lines to be added here... -->

<!-- (you don't need this if you are using a .RELEASE version) -->
<repositories>
    <repository>
        <id>spring-snapshots</id>
        <url>http://repo.spring.io/snapshot</url>
        <snapshots><enabled>true</enabled></snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <url>http://repo.spring.io/milestone</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-snapshots</id>
        <url>http://repo.spring.io/snapshot</url>
    </pluginRepository>
    <pluginRepository>
        <id>spring-milestones</id>
        <url>http://repo.spring.io/milestone</url>
    </pluginRepository>
</pluginRepositories>
然后開心的mvn package,就報錯了。錯誤如下:
>Non-resolvable parent POM: Could not find artifact org.springframework.boot:spring-boot-starter-parent:pom:1.3.2.BUILD-SNAPSHOT in ibiblio (http://mirrors.ibiblio.org/pub/mirrors/maven2/) and 'parent.relativePath' points at wrong local POM @ line 10, column 13 -> [Help 2]

百思不得其姐啊,maven 應該是先找當前項目的repository,然后找本地,然后再找私服,最后找中央倉庫才對啊!明明在pom.xml里面配置了repository了啊!

## 解決方案
今天有點時間,自己分析了下然后Google了下,解決了這個問題。問題原因及方案如下:

> 我的maven中的setting.xml配置文件里面關於mirror部分的配置如下:
```xml```
<mirror>
    <id>ibiblio</id>
    <mirrorOf>*</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>

錯誤就出在mirrorOf節點了,如果寫*會覆蓋掉所有的,不管是哪個repository,最后都被這個鏡像所mirror掉了,導致pom文件中的repository不生效了。
解決方案也很簡單,把這個mirrorOf改掉就好了。具體修改建議參考maven官方說明:

* = everything
external:* = everything not on the localhost and not file based.
repo,repo1 = repo or repo1
*,!repo1 = everything except repo1

擴展知識

  1. maven的私服配置:http://my.oschina.net/liangbo/blog/195739
  2. 深入比較幾種maven倉庫的優先級:http://toozhao.com/2012/07/13/compare-priority-of-maven-repository/
  3. http://maven.apache.org/guides/mini/guide-mirror-settings.html
  4. Maven最佳實踐--Maven倉庫:http://juvenshun.iteye.com/blog/359256
  5. Maven倉庫管理之Nexus:http://my.oschina.net/aiguozhe/blog/101537

其它需要注意的問題及推薦

  1. 盡量不要配置mirrorOf為*
  2. 私服的配置推薦用profile配置而不是mirror(畢竟mirror是鏡像,私服其實是n個鏡像及自己的開發庫等的合集)

xml

nexus


nexus
http://192.168.163.xx:xx/nexus/content/groups/public/

true


true





nexus
http://192.168.163.xx:xx/nexus/content/groups/public/

true


true






nexus


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM