阅读此篇一定要熟练使用过MAVEN
1、新建Nexus私人服务器。这个不多说了,网上很多
2、配置本地maven setting.xml 这个网上也很多,不过这里也花了一点时间。来说说经历吧
1)、若需要从私人服务器上下载文件可以配置。在<profiles></profiles>下面,添加
<profile>
<id>nexus</id>
<repositorys>
<repository>
<id>pubc</id>
<name>Pub Repositories</name>
<url>http://172.18.22.41:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositorys>
<pluginRepositories>
<pluginRepository>
<id>publ</id>
<name>Public Retories</name>
<url>http://172.18.22.41:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
这段代码不用仔细研究,只需注意的是URL一定要配置正确,他是公共集合地址上私人服务器上的,同时需要激活此profile 注意激活名称就是profile下的ID
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
还有一个镜像,就是完全遵从私人服务器的内容,而不会去中央仓库或者其它第三方去找JAR包,我自己不支持这个使用,因为有了就有些JAR包不能下载
这里也无需多说
----------------------------------------------------------------------------------------------------------------------------------------------------------
2)\上传jar包
需要在自己的pom文件 中新增 仓库管理
<distributionManagement>
<repository>
<id>nexus-release</id>
<url>http://172.18.22.41:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://172.18.22.41:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
这里包含了releases和snapshots
一般deploy会选择snapshots
二般情况下,如果使用releases插件刚会选择releases目录上传 具体releases插件后面会讲,这是才是版本管理重点
若需要上传成功还需要有maven。setting.xml中新增私人服务器的用户名 密码
在<servers></servers>中
<server>
<id>nexus-release</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
注意ID一定要对应
这样子可以上传下载就完成啦
最后就是版本发布了这个是本章重点
1、maven项目中有很多的继承,聚合关系
要发布版本,不能只发布里面的子模块,需要整体发布。因为里面的继承关系错综复杂若有快照引用则一定打包失败(什么叫快照,去百度)
2、确保maven项目内没有错误,有错误一定发布失败,不过这个可以在打包的时候有日志可以查看哪里报错
要发布版本控制首先要看SCM是什么东西
SCM是对版本管理的maven管理比如svn git等,里面可以在pom文件 中配置地址
<scm>
<connection>scm:svn:svn://172.18.88.81/svn/P16031101绍兴车载4G-wifi路由器/2软件/06.advert/web/Hik_Module</connection>
<developerConnection>scm:svn:svn://172.18.88.81/svn/P16031101绍兴车载4G-wifi路由器/2软件/06.advert/web/Hik_Module</developerConnection>
</scm>
格式需要注意,这个地址是模块在svn上的地址,前辍<connection>scm:版本管理工具:地址</connection>
a:具体能不能用,需要将里面的地址放到自己的客户端测一下,我就是这里给绊住了
b:可以在MVN的环境下采用命令测试,比如mvn scm:update mvn scm:checkout mvn scm:checkin 等等 这个测可能会出现以下问题
......在eclipse中出现不是此副本的情况 ,要求你svn--->upgrade 此时可能是eclipse SVN插件与本地客户端不一致,而SCM命令可能是需要本地的客户端来使用,
此时可以打开工作空间所在的位置,右击upgrade 升级为本地的SVN客户端 控制,此时可以使用SCM命令了
SCM确保能用之后,再来看release是如何发布的。
1在pom.xml文件 中加maven-release-plugin些插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<tagBase>svn://****/svn/P16031101绍兴车载4G-wifi路由器/2软件/06.advert/web/tag/Hik_Module</tagBase>
<branchBase>svn://****/svn/P16031101绍兴车载4G-wifi路由器/2软件/06.advert/web/branch/Hik_Module</branchBase>
</configuration>
</plugin>
tag和branch分支要分配好,否则格局太乱,以后很难管理,如果问我tag 和branch是什么,那我无语了
模块地址要对应好,A模块要对应到A模块下面,比如我这里的Hik_Module对应在了Hik_Module文件夹下面
再说一次
要发布版本,不能只发布里面的子模块,需要整体发布。因为里面的继承关系错综复杂若有快照引用则一定打包失败(什么叫快照,去百度)
敲下命令mvn release:prepare
此时是打包到了target下面,同时上传到svn的tag。同时本模块下所有的快照版本被自动升级了 比如原先的1.0.0-SNAPSHOT变为了1.0.1-SNAPSHOT
若有日志错误则依据日志错误排错
敲下命令mvn release:perform
上传到了本地私人服务器上了