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

针对公司内网私服仓库,私服仓库不能访问外网,此时无法在私服仓库代理阿里的maven仓库。我们的maven就需要配置多个仓库(maven目录下的conf/settings.xml配置文件):

一、多仓库配置

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

    <profile><id>nexus</id><repositories><repository><id>maven-releases</id><url>http://192.168.0.54:8899/ajco/repository/maven-releases/</url><releases><enabled>true</enabled><updatePolicy>always</updatePolicy> </releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></repository><repository><id>maven-snapshots</id><url>http://192.168.0.54:8899/ajco/repository/maven-snapshots/</url><releases><enabled>true</enabled><updatePolicy>always</updatePolicy> </releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></repository></repositories><pluginRepositories><pluginRepository><id>maven-releases</id><url>http://192.168.0.54:8899/ajco/repository/maven-releases/</url><releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></pluginRepository><pluginRepository><id>maven-snapshots</id><url>http://192.168.0.54:8899/ajco/repository/maven-snapshots/</url><releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases><snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots></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>

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

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

说明:

        1.这里aliyun仓库的id设置为central,则会覆盖maven里默认的远程仓库。

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

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

二、配置maven deploy

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

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

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

    <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>

 

本文链接:https://my.lmcjl.com/post/3953.html

展开阅读全文

4 评论

留下您的评论.