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>

 

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

 

posted @ 2019-08-20 15:37  露娜妹  阅读(4604)  评论(0编辑  收藏  举报