Nexus私服让我们可以在企业内部从同一个私服下载Maven仓库里面的dependency和plugin.很方便,不过昨天碰到的一个问题是,有一个仓库加入到Nexus后不能,Maven工程无法通过Nexus私服下载该仓库的dependency。
这个仓库叫做:http://download.osgeo.org/webdav/geotools/
想了一个办法绕过它,通过Maven的~/.m2/settings.xml中配置两个Mirror,在遇到osgeo的时候直接使用该仓库,而在其他情况下用私服。
下面是配置:
- <settings>
- <servers>
- <server>
- <id>snapshots</id>
- <username>admin</username>
- <password>admin</password>
- </server>
- </servers>
- <pluginGroups>
- <pluginGroup>org.apache.maven.plugins</pluginGroup>
- </pluginGroups>
- <mirrors>
- <mirror>
- <!–This sends everything else to /public –>
- <id>nexus</id>
- <mirrorOf>external:*,!osgeo</mirrorOf>
- <url>http://my-proxy:8080/nexus/content/groups/public</url>
- </mirror>
- <mirror>
- <id>osgeo</id>
- <mirrorOf>osgeo</mirrorOf>
- <name>Open Source Geospatial Foundation Repository</name>
- <url>http://download.osgeo.org/webdav/geotools/</url>
- </mirror>
- </mirrors>
- <profiles>
- <profile>
- <id>nexus</id>
- <!–Enable snapshots for the built in central repo to direct –>
- <!–all requests to nexus via the mirror –>
- <repositories>
- <repository>
- <id>central</id>
- <url>http://central</url>
- <releases><enabled>true</enabled></releases>
- <snapshots><enabled>true</enabled></snapshots>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>central</id>
- <url>http://central</url>
- <releases><enabled>true</enabled></releases>
- <snapshots><enabled>true</enabled></snapshots>
- </pluginRepository>
- </pluginRepositories>
- </profile>
- </profiles>
- <activeProfiles>
- <!–make the profile active all the time –>
- <activeProfile>nexus</activeProfile>
- </activeProfiles>
- </settings>
而在maven工程里面如下配置,注意repository.id必须和mirror.id相等。
- <repositories>
- <repository>
- <id>local repository</id>
- <url>http://my-proxy:8080/nexus/content/groups/public/</url>
- </repository>
- <repository>
- <id>osgeo</id>
- <name>Open Source Geospatial Foundation Repository</name>
- <url>http://download.osgeo.org/webdav/geotools/</url>
- </repository>
- </repositories>