歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Maven 靈活使用不同的倉庫

Maven 靈活使用不同的倉庫

日期:2017/2/28 15:47:14   编辑:Linux教程

Nexus私服讓我們可以在企業內部從同一個私服下載Maven倉庫裡面的dependency和plugin.很方便,不過昨天碰到的一個問題是,有一個倉庫加入到Nexus後不能,Maven工程無法通過Nexus私服下載該倉庫的dependency。

這個倉庫叫做:http://download.osgeo.org/webdav/geotools/

想了一個辦法繞過它,通過Maven的~/.m2/settings.xml中配置兩個Mirror,在遇到osgeo的時候直接使用該倉庫,而在其他情況下用私服。

下面是配置:

  1. <settings>
  2. <servers>
  3. <server>
  4. <id>snapshots</id>
  5. <username>admin</username>
  6. <password>admin</password>
  7. </server>
  8. </servers>
  9. <pluginGroups>
  10. <pluginGroup>org.apache.maven.plugins</pluginGroup>
  11. </pluginGroups>
  12. <mirrors>
  13. <mirror>
  14. <!--This sends everything else to /public -->
  15. <id>nexus</id>
  16. <mirrorOf>external:*,!osgeo</mirrorOf>
  17. <url>http://my-proxy:8080/nexus/content/groups/public</url>
  18. </mirror>
  19. <mirror>
  20. <id>osgeo</id>
  21. <mirrorOf>osgeo</mirrorOf>
  22. <name>Open Source Geospatial Foundation Repository</name>
  23. <url>http://download.osgeo.org/webdav/geotools/</url>
  24. </mirror>
  25. </mirrors>
  26. <profiles>
  27. <profile>
  28. <id>nexus</id>
  29. <!--Enable snapshots for the built in central repo to direct -->
  30. <!--all requests to nexus via the mirror -->
  31. <repositories>
  32. <repository>
  33. <id>central</id>
  34. <url>http://central</url>
  35. <releases><enabled>true</enabled></releases>
  36. <snapshots><enabled>true</enabled></snapshots>
  37. </repository>
  38. </repositories>
  39. <pluginRepositories>
  40. <pluginRepository>
  41. <id>central</id>
  42. <url>http://central</url>
  43. <releases><enabled>true</enabled></releases>
  44. <snapshots><enabled>true</enabled></snapshots>
  45. </pluginRepository>
  46. </pluginRepositories>
  47. </profile>
  48. </profiles>
  49. <activeProfiles>
  50. <!--make the profile active all the time -->
  51. <activeProfile>nexus</activeProfile>
  52. </activeProfiles>
  53. </settings>

而在maven工程裡面如下配置,注意repository.id必須和mirror.id相等。

  1. <repositories>
  2. <repository>
  3. <id>local repository</id>
  4. <url>http://my-proxy:8080/nexus/content/groups/public/</url>
  5. </repository>
  6. <repository>
  7. <id>osgeo</id>
  8. <name>Open Source Geospatial Foundation Repository</name>
  9. <url>http://download.osgeo.org/webdav/geotools/</url>
  10. </repository>
  11. </repositories>
Copyright © Linux教程網 All Rights Reserved