20200420 maven私服配置

Maven私服配置的兩種方式

以下配置均在settings.xml中配置,私服配置不建議配置在某個項目的 pom.xml文件中。

1、鏡像方式配置。

maven 在默認情況下是從中央倉庫下載構建,也就是 id 爲 central 的倉庫。如果沒有特殊需求,一般只需要將私服地址配置爲鏡像,同時配置其代理所有的倉庫就可以實現通過私服下載依賴的功能。(通過私服代理所有的倉庫)

 

當按照以上方式配置之後,所有的依賴下載請求都將通過私服下載。

2、遠程倉庫方式配置

使用覆蓋默認 central 倉庫的方式來配置私服。

此配置中的遠程倉庫 id 是 central,也就是中央倉庫的 id,這麼配置的原因就是使用當前配置的私服地址覆蓋默認的中央倉庫地址。

以上兩種方式都可以實現配置 maven 私服的功能,個人建議使用鏡像的方式配置,最方便簡單,不易出錯,同時將訪問外部倉庫的職責全部丟給私服,方便私服統一管理。

 

pom.xml中repositories、pluginRepository的作用

用來配置maven項目的遠程倉庫。用來配置maven插件的遠程倉庫。

如果我們創建一個項目,就需要配置一次。可以將遠程倉庫配置在maven的setting.xml裏面.這樣就可以實現只配置一次。

snapshots默認是關閉的,需要開啓。是否支持快照版本,是否支持release版本?

    <repositories>
        <repository>
            <id>nexus</id>
            <url>http://192.168.141.110:8082/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <url>http://192.168.141.110:8082/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

在pom.xml中使用distributionManagement將項目打包上傳到nexus私服。

    <distributionManagement>
        <repository>
            <id>nexus</id>
            <name>Pica 3rdParty Repository</name>
            <url>http://192.168.141.110:8082/repository/pica-3rdParty/</url>
        </repository>
    </distributionManagement>

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章