问题描述
昨天晚上想用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
扩展知识
- maven的私服配置:http://my.oschina.net/liangbo/blog/195739
- 深入比较几种maven仓库的优先级:http://toozhao.com/2012/07/13/compare-priority-of-maven-repository/
- http://maven.apache.org/guides/mini/guide-mirror-settings.html
- Maven最佳实践--Maven仓库:http://juvenshun.iteye.com/blog/359256
- Maven仓库管理之Nexus:http://my.oschina.net/aiguozhe/blog/101537
其它需要注意的问题及推荐
- 尽量不要配置mirrorOf为*
- 私服的配置推荐用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