在使用過程中,Maven默認配置是不能下載SNAPSHOT包的,這是基於一種代碼穩定性進行考量得出的結論。引入SNAPSHOT包最大的問題就是,由於SNAPSHOT允許重復上傳,所以引用一個這樣的包開發的代碼有可能在使用過程中會頻繁出現接口變更,這會導致開發者疑惑,並不清楚究竟是什么引發的問題。但是在自建項目中,這個特性又非常有用,尤其是需要新加接口時,每加個接口都發布一個release版本顯然不合理。而同一團隊基於一個SNAPSHOT進行開發顯然溝通成本極小,可以支持頻繁迭代和更改,發布模塊顯然比通過git subtree引用其他代碼來的更簡潔更模塊化,適合團隊內部開發使用。
目前我們常用的修改倉庫方式是在settings里新建一個mirror如下:
<mirrors> <mirror> <id>nexus</id> <name>private maven</name> <url>http://xxxxxx:8081/repository/maven-public/</url> <mirrorOf>*</mirrorOf> </mirror> </mirrors>
這種方式是引入外部mirror的時候使用的,如果要下載SNAPSHOT包,此種方式並不能滿足要求,可以將這段配置注釋掉,不影響私有倉庫配置。我們可以手工配置profile的方式拉取倉庫中的SNAPSHOT包,具體配置如下:
<profiles> <profile> <id>nexus</id> <repositories> <repository> <id>central</id> <name>private maven</name> <url>http://xxxxxxx:8081/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <name>private maven</name> <url>http://xxxxxx:8081/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles>
使用snapshots enabled啟用SNAPSHOT包下載,並一定要把對應的profile ID加入到activeProfiles中,這樣就可以提供SNAPSHOT服務了。
PS:SNAPSHOT穩定了記得發布個release版本,畢竟發布多了可能忘了SNAPSHOT是什么版本了。