最近公司人事變革,一批人員被離職,瞬間感覺壓力大增,我一個做android,想要頂起後台接口的活,真是有點吃力,已經30了,還在各種苦逼,但是做為技術控,這種快樂別人無法理解。這幾天Check Out後台代碼,無奈跑不起來,Mac系統Maven構建實在蛋疼,於是恨起來後台組的哥們為什麼不搭建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.)
<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://127.0.0.1:8081/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>
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,原因正在調查中。