最近從SVN下載的代碼,在本地構建時出現了諸多問題,部分依賴下載超時,就想起在局域網搭建Maven私服,廢話不說了,在測試服務器上建的已經成功,就隨便找台機子再練習一遍順道寫個日志。
1、前往http://www.sonatype.com/download-oss-sonatype下載Nexus-Bundle
下載地址:http://www.sonatype.org/downloads/nexus-latest-bundle.zip
2、解壓下載的nexus-2.13.0-01-bundle
3、安裝並nexus服務
更改nexus服務端口(可選步驟)
這里使用默認端口 8081
5、修改用戶Maven配置文件,%userprofile%\.m2\setting.xml
Content of setting.xml (You should replace `username`,`password` & `url` in the file if you have changed them.)
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <servers> <server> <id>releases</id> <username>admin</username> <password>adminsa</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>adminsa</password> </server> </servers> <mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://192.168.1.222:7758/nexus/content/groups/public/</url> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <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> <activeProfile>nexus</activeProfile> </activeProfiles> </settings>
6、客戶端配置(假定已經配置好Maven運行環境)
為pom.xml添加Maven私服配置
Content of add item
<repositories> <repository> <id>nexus</id> <name>Team Nexus Repository</name> <url>http://127.0.0.1:8081/nexus/content/groups/public</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>Team Nexus Repository</name> <url>http://127.0.0.1:8081/nexus/content/groups/public</url> </pluginRepository> </pluginRepositories>
7、客戶端測試(需要有Maven項目,沒有點擊下載 A Simple Maven Project)
進入到Maven項目目錄(pom.xml所在目錄)
8、驗證Maven私服(Repositories -> Repository Path[Central])
9、看到剛剛使用 mvn clean命令下載的plexus-utils-3.0已經在私服倉庫中,這時如果局域網內其他機器測試就會直接從私服上下載,為項目構建節省資源。
可以看到在另一台機器上已經下載一上午的結果(Mac系統有時候讓人很無語)
再看看修改了pom.xml后再看看構建是個什么樣子吧
構建完成,是不是感覺用起來很爽,值得一提的是,其他客戶機上同樣需要在用戶目錄的.m2子目錄中創建setting.xml配置上Maven私服。在Intellij Idea上直接 update indecies還不行,明明已經配置了使用下載的Maven,原因正在調查中。