研發團隊考慮使用 Jenkins 進行一鍵構建、部署服務,其中構建使用 Maven 進行,構建時需要從 Maven 倉庫中下載所需依賴,因此項目的各個模塊 jar 包需要上傳到本地私有倉庫中供 Maven 構建時下載。
- 下載 Maven 程序包並解壓縮到倉庫服務器,啓動服務,地址爲:
http://172.22.151.183:8081/
- 配置 Jenkins 服務所在機器的 Maven , 配置文件路徑:
C:\Users\Administrator\.m2\settings.xml
- 配置文件完整內容:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<pluginGroups />
<proxies />
<servers>
<server>
<id>maven-thirdpart</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>maven-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>maven-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>maven-public</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<localRepository>C:\Users\Administrator\.m2\repository</localRepository>
<mirrors>
<mirror>
<id>maven-snapshots</id>
<mirrorOf>*</mirrorOf>
<url>http://172.22.151.183:8081/repository/maven-snapshots/</url>
</mirror>
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven jcenter</name>
<url>https://maven.aliyun.com/repository/jcenter</url>
</mirror>
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
<mirror>
<id>ibiblio</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>
<mirror>
<id>jboss-public-repository-group</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>google-maven-central</id>
<name>Google Maven Central</name>
<url>https://maven-central.storage.googleapis.com
</url>
<mirrorOf>central</mirrorOf>
</mirror>
<!-- 中央倉庫在中國的鏡像 -->
<mirror>
<id>maven.net.cn</id>
<name>oneof the central mirrors in china</name>
<url>http://maven.net.cn/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
- 項目模塊 pom 文件配置:
<!-- 構件依賴倉庫 -->
<repositories>
<repository>
<id>maven-snapshots</id>
<url>http://172.22.151.183:8081/repository/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<!-- <updatePolicy>always</updatePolicy> -->
</snapshots>
</repository>
</repositories>
<!-- 插件倉庫 -->
<pluginRepositories>
<pluginRepository>
<id>maven-public</id>
<url>http://172.22.151.183:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<!-- 發佈倉庫 -->
<distributionManagement>
<snapshotRepository>
<id>maven-snapshots</id>
<name>maven-snapshots</name>
<url>http://172.22.151.183:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
以上,就是最最最簡略的配置,甚至沒有配置 release 發佈版本倉庫,因爲我們項目目前需求只是 snapshot 快照版本,能夠把依賴模塊編譯打包上傳、web 服務模塊構建時能夠下載所需的依賴模塊 jar 包即可。