Maven配置私有仓库

前言

当公司或个人具有自己独有的jar时,不想公开,一般就会放在自己的私有Maven仓库中,在项目中需要引用,此时就需要将公司私有仓库配置到maven当中,一般我们的maven配置的都是aliyun的maven公有仓库,但此时我们不但要配置私有仓库还要配置公有仓库,因为有的公有jar,私有仓库中不一定有,所以此时就涉及到maven多仓库配置喽。

maven配置一共分为两种

  1. 统一配置,通过maven的setting.xml文件配置,每个项目都可直接使用。
  2. 项目配置,在项目的pom.xml文件中配置(有得项目需要进行定制化配置,但其他项目又不需要这个仓库)

以下使用的统一配置方式来进行配置哈。项目配置可自行百度。希望可以帮助到大家。

1、Setting.xml

在本地maven的setting.xml配置文件中进行私有仓库配置。

Maven配置私有仓库

在标签中配置仓库访问账号和密码。
在标签中配置仓库地址。
在标签中配置多仓库使用。
在中激活仓库,否则配置无效。

<mirrors>
    <mirror>
        <id>nexus-repository</id>
        <mirrorof>central</mirrorof>
        <name>Nexus repository</name>
        <url>http://192.168.0.1::8081/content/groups/public/</url>
    </mirror>
    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>\
        <mirrorof>central</mirrorof>
    </mirror>
</mirrors>
<profiles>
    <profile>
        <id>repository</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>

    <profile>
        <id>alimaven</id>
        <repositories>
            <repository>
                <id>central</id>
                <url>http://central</url>
                <releases><enabled>true</enabled></releases>
                <snapshots><enabled>true</enabled></snapshots>
            </repository>
            <repository>
                <id>Dcm4Che</id>
                <name>Dcm4Che</name>
                <url>http://www.dcm4che.org/maven2/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginrepositories>
            <pluginrepository>
                <id>nexus</id>
                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginrepository>
        </pluginrepositories>
    </profile>
</profiles>
<activeprofiles>
    <activeprofile>repository</activeprofile>
    <activeprofile>alimaven</activeprofile>
</activeprofiles>

2、刷新IDEA项目

查看maven仓库引用

Maven配置私有仓库

此刻配置就成功了,即可使用远程私有仓库拉去jar,如果找不到相关jar,会自动去aliyun中央仓库下载公有maven坐标。

Original: https://www.cnblogs.com/aerfazhe/p/16396271.html
Author: 阿尔法哲
Title: Maven配置私有仓库

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/643325/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球