1. maven配置连接nexus
a) settings.xml文件中增加profile
<profiles> <profile> <id>nexusProfile</id> <repositories> <repository> <id>nexus</id> <name>Nexus Repository</name> <url>http:// http://myrepos.mvn.com/:8081/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> <!-- 默认时关闭的,需要手动开启 --> </snapshots> </repository> </repositories> </profile> </profiles>
b) 激活profile,在settings.xml文件中增加
<!-- 激活profile配置 --> <activeProfiles> <activeProfile>nexusProfile</activeProfile> </activeProfiles>
c) 此时执行mvn compile将会通过http://myrepos.mvn.com私服下载依赖包,但是私服的storage是空的,那么会经过私服链接到默认中央库下载依赖包,并且所有下载的依赖包会在私服的storage上存储,此时查看browse storage会发现有内容了,私服本地storage(nexus-2.12.0-01-bundle/sonatype-work/nexus/storage/central)中也有内容了
2. maven配置镜像
a) 工厂的镜像,只要mirrorOf中的工厂要被访问,就会自动来找镜像,如果镜像的url中无法访问,就不会去别的地方找了
b) settings.xml文件中增加
<mirrors> <mirror> <id>nexusMirror</id> <mirrorOf>nexus,central</mirrorOf><!-- 哪些工厂要用镜像,*表示所有工厂都是用这个镜像,这是推荐做法 --> <name>Human Readable Name for this Mirror.</name> <url>http:// myrepos.mvn.com:8081/nexus/content/groups/public/</url> </mirror> </mirrors>
c) 此时关闭私服,再执行mvn compile,工程就不会从默认工厂下载依赖包,会报错
3. maven配置发布
a) settings.xml文件中增加
<servers> <server> <id>smi-release</id> <username>admin</username> <password>admin123</password> </server> <server> <id>smi-snapshot</id> <username>admin</username> <password>admin123</password> </server> </servers>
b) 上面配置中的id要与项目pom.xml中<distributionManagement>元素中的id一致
4. pom.xml配置发布
a) pom.xml文件中增加
<distributionManagement> <repository> <id>smi-release</id> <name>smi release first deploy</name> <url>http:// http://myrepos.mvn.com/:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>smi-snapshot</id> <name>smi snapshot first deploy</name> <url>http:// http://myrepos.mvn.com/:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
<id> smi-release </id>,<id> smi-snapshot </id>要与settings.xml中<server>属性中的id一致,deploy时,会检查pom.xml的该id,匹配到setting.xml中的id取得nexus私服的帐号密码获得提交权限
还没有评论,来说两句吧...