天天看點

maven配置私服倉庫

公司都有自己的私服倉庫,配置之後可以提高下載下傳速度,同時本公司自己項目的依賴都在私服倉庫裡,有些東西是外界無法通路的,僅僅是内部使用。

私服是一種特殊的遠端倉庫,它是架設在區域網路内的倉庫服務,私服代理廣域網上的遠端倉庫,供區域網路内的Maven使用者使用。當Maven需要下載下傳構件的時候,它從私服請求,如果私服上不存在該構件,則從外部的遠端倉庫下載下傳,緩存在私服上之後,再為Maven的下載下傳請求提供服務。我們還可以把一些無法從外部倉庫下載下傳到的構件上傳到私服上。

比如你們公司的私服倉庫位址是:http://nexus.company.com/repository/maven-public/

那麼就在pom.xml裡配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <repositories>
        <repository>
            <id>nexus</id>
            <url>http://nexus.company.com/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <url>http://nexus.company.com/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>      

情況二:比如我要與A公司對接,對方提供了maven坐标,可是你引入後報錯 找不到此依賴。那是因為你們的私服倉庫以及中央倉庫沒有人家的私有項目。那就要對方提供他們的倉庫位址,然後配置即可。

比如對方位址為:http://artifactory.other-company.com/artifactory/maven/

就要如下配置,也就是說,可以配置多個私服倉庫。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <repositories>
        <repository>
            <id>nexus</id>
            <url>http://nexus.company.com/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>nexus-other-company</id>
            <url>http://artifactory.other-company.com/artifactory/maven/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <url>http://nexus.company.com/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>nexus-other-company</id>
            <url>http://artifactory.other-company.com/artifactory/maven/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>      

配置完你就可以正常引入别人的私有項目依賴了。

小LUA

面對敵人的嚴刑逼供,我一個字也沒說,而是一五一十寫了下來。