maven多仓库配置 公司仓库和阿里仓库

针对公司内网私服仓库,私服仓库不能访问外网,此时无法在私服仓库代理阿里的maven仓库。我们的maven就需要配置多个仓库:

maven目录下的conf/settings.xml配置文件:

一、在profiles标签内新建profile,配置一个公司的仓库和阿里的仓库;

复制代码

    <profile>
        <id>nexus</id>
        <repositories>
            <!-- 私服发布仓库,即私服正式jar仓库 -->
            <repository>
                <id>maven-releases</id>
                <url>http://192.168.0.54:8899/ajco/repository/maven-releases/</url>
            </repository>
            <!-- 私服快照仓库,即私服临时jar仓库 -->
            <repository>
                <id>maven-snapshots</id>
                <url>http://192.168.0.54:8899/ajco/repository/maven-snapshots/</url>
            </repository>
        </repositories>
        <!-- 私服插件仓库,一般插件都是从外网仓库下载,可以不用配置 -->
        <pluginRepositories>
            <pluginRepository>
                <id>maven-releases</id>
                <url>http://192.168.0.54:8899/ajco/repository/maven-releases/</url>
            </pluginRepository>
            <pluginRepository>
                <id>maven-snapshots</id>
                <url>http://192.168.0.54:8899/ajco/repository/maven-snapshots/</url>
            </pluginRepository>
        </pluginRepositories>
    </profile>
    <profile>
        <id>aliyun</id>
        <repositories>
            <!-- 外网仓库,用国内阿里仓库 -->
            <repository>
                <id>central</id>
                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>central</id>
                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            </pluginRepository>
        </pluginRepositories>
    </profile>

复制代码

 

二、在activeProfiles标签内配置activeProfile,激活上面的仓库,activeProfile里的值对应上面profile里的id值

    <activeProfile>nexus</activeProfile>
    <activeProfile>aliyun</activeProfile>

 

    说明:

        1.maven有个默认的外网中央仓库,id是central。在mirrors标签内配置一个mirrorOf=central的镜像,则使用这个镜像地址替换这个外网中央仓库;

        2.profiles标签里的aliyun的仓库也可以不用配置,直接在mirrors标签内配置一个镜像仓库,mirrors镜像仓库mirrorOf的值设置为central,则也可以实现覆盖默认的仓库

复制代码

    <mirror>
        <id>alimaven</id>
        <mirrorOf>central</mirrorOf>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    </mirror>

复制代码

 

配置maven deploy:

    如果需要将本地项目deploy打包上传到私服仓库,则需要配置如下信息:

一、在settings.xml的servers标签内新建server标签,定义一个登录私服的账号密码配置;

    <server>
        <id>deploymentRepo</id>
        <username>repouser</username>
        <password>repopwd</password>
    </server>

 

二、项目的pom.xml文件加入如下配置,id对应上面的server里的id,表示deploy时上传到下面的仓库,用上面的账号密码;

    说明:本地项目version如果以-snapshots结尾,maven则自动选择上传到snapshotRepository仓库,即配置的快照仓库,否则上传到发布仓库。

 

复制代码

    <distributionManagement>
        <repository>
            <id>deploymentRepo</id>
            <url>http://192.168.0.54:8899/ajco/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>deploymentRepo</id>
            <url>http://192.168.0.54:8899/ajco/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

复制代码

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值