针对公司内网私服仓库,私服仓库不能访问外网,此时无法在私服仓库代理阿里的maven仓库。我们的maven就需要配置多个仓库:
maven目录下的conf/settings.xml配置文件:
一、在profiles标签内新建profile,配置一个公司的仓库和阿里的仓库;
<profile> nexus <!-- 私服发布仓库,即私服正式jar仓库 --> maven-releases http://192.168.0.54:8899/ajco/repository/maven-releases/ <!-- 私服快照仓库,即私服临时jar仓库 --> maven-snapshots http://192.168.0.54:8899/ajco/repository/maven-snapshots/ maven-releases http://192.168.0.54:8899/ajco/repository/maven-releases/ maven-snapshots http://192.168.0.54:8899/ajco/repository/maven-snapshots/ aliyun central http://maven.aliyun.com/nexus/content/groups/public/ central http://maven.aliyun.com/nexus/content/groups/public/
二、在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,则也可以实现覆盖默认的仓库
alimaven central aliyun maven http://maven.aliyun.com/nexus/content/groups/public/
配置maven deploy:
如果需要将本地项目deploy打包上传到私服仓库,则需要配置如下信息:java 框架案例 www.1b23.com
一、在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>