====== maven-scm-plugin插件和maven-release-plugin插件的介绍 ======
===== 背景 =====
项目SNAPSHOT快照版本开发到一个阶段后,需要发布一个release稳定版本。一次正式的发布需要这样一些工作:
- 在trunk中,更新pom版本从0.0.1-SNAPSHOT到0.0.1
- 对0.0.1打一个svn tag
- 针对tag进行mvn deploy,发布稳定版本
- 更新trunk从0.0.1到0.0.2-SNAPSHOT
当然0.0.1后面紧跟的不一定是0.0.2,规范的maven版本应该是:<主版本>.<次版本>.<增量版本>
* 主版本一般来说代表了项目的重大的架构变更
* 次版本一般代表了一些功能的增加或变化,但没有架构的变化
* 增量版本,一般是一些小的bug fix,不会有重大的功能变化
所以0.0.1后面可能是0.1.1也可能是1.0.1,不一定是0.0.2
接着上面继续讲,每次正式的发布你都可以手工一步步的做这些事情,无非就是一些svn操作,一些pom编辑,还有一些mvn操作。但是重复手工做这些事情,一来繁琐,而来容易出错。因此maven-scm-plugin插件和maven-release-plugin插件就是用来自动化这一系列动作。
===== 操作 =====
==== pom.xml源码 ====
注意其中的:
* scm软件配置管理
* nexus私服仓库
* scm软件配置管理插件
* 版本发布插件
* 版本发布管理
4.0.0
com.gxx
record
war
0.0.1-SNAPSHOT
record Maven Webapp
http://maven.apache.org
4.0.5.RELEASE
1.6.9
1.6.1
2.3.20
3.2.7
1.2.2
1.3.2
2.4
2.0
1.2
1.1.2
2.4.0
2.4.0
2.4.0
2.4.0
4.11
1.2.16
5.1.9
1.4
scm:svn:svn://121.43.104.34/gxx/trunk/record
scm:svn:svn://121.43.104.34/gxx/trunk/record
org.springframework
spring-core
${spring.version}
org.springframework
spring-beans
${spring.version}
org.springframework
spring-context
${spring.version}
org.springframework
spring-context-support
${spring.version}
org.springframework
spring-aop
${spring.version}
org.springframework
spring-jdbc
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-webmvc
${spring.version}
org.aspectj
aspectjrt
${aspectjrt.version}
org.aspectj
aspectjweaver
${aspectjweaver.version}
org.freemarker
freemarker
${freemarker.version}
org.mybatis
mybatis
${mybatis.version}
org.mybatis
mybatis-spring
${mybatis-spring.version}
org.mybatis.generator
mybatis-generator-core
${mybatis-generator-core.version}
javax.servlet
servlet-api
${servlet-api.version}
provided
javax.servlet.jsp
jsp-api
${jsp-api.version}
provided
javax.servlet
jstl
${jstl.version}
taglibs
standard
${standard.version}
com.fasterxml.jackson.core
jackson-databind
${jackson-databind.version}
com.fasterxml.jackson.core
jackson-annotations
${jackson-annotations.version}
com.fasterxml.jackson.module
jackson-module-jaxb-annotations
${jackson-module-jaxb-annotations.version}
com.fasterxml.jackson.core
jackson-core
${jackson-core.version}
log4j
log4j
${log4j.version}
junit
junit
test
${junit.version}
mysql
mysql-connector-java
${mysql-connector-java.version}
commons-dbcp
commons-dbcp
${commons-dbcp.version}
nexus
Team Nexus Repository
http://121.43.104.34:8081/nexus/content/groups/public
offical
Maven Official Repository
http://repo1.maven.org/maven2
false
spring-milestone
Spring Maven MILESTONE Repository
http://maven.springframework.org/milestone
jboss
Jboss Repository
http://repository.jboss.org/nexus/content/groups/public-jboss/
false
java.net
Java.net Repository
http://download.java.net/maven/2/
false
spring-release
Spring Maven Release Repository
http://repo.springsource.org/libs-release
false
record
org.apache.maven.plugins
maven-compiler-plugin
2.0.2
1.6
1.6
utf8
org.apache.maven.plugins
maven-scm-plugin
1.3
org.apache.maven.plugins
maven-release-plugin
2.4
svn://121.43.104.34/gxx/tags/record
svn://121.43.104.34/gxx/branches/record
org.apache.maven.plugins
maven-archetype-plugin
2.2
nexus-releases
Nexus Release Repository
http://121.43.104.34:8081/nexus/content/repositories/releases/
nexus-snapshots
Nexus Snapshot Repository
http://121.43.104.34:8081/nexus/content/repositories/snapshots/
==== 操作步骤 ====
D:\05.HeadWorkspace\record>mvn release:prepare #进入项目目录,dir会看到pom.xml,当前版本是0.0.1-SNAPSHOT,执行脚本
###############################################################################
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building record Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.4:prepare (default-cli) @ record ---
[INFO] Resuming release from phase 'scm-check-modifications'
[INFO] Verifying that there are no local modifications...
[INFO] ignoring changes on: **\release.properties, **\pom.xml.next, **\pom.xml
.releaseBackup, **\pom.xml.backup, **\pom.xml.branch, **\pom.xml.tag
[INFO] Executing: cmd.exe /X /C "svn --non-interactive status"
[INFO] Working directory: D:\05.HeadWorkspace\record
[INFO] Checking dependencies and plugins for snapshots ...
What is the release version for "record Maven Webapp"? (com.gxx:record) 0.0.1: :
###############################################################################
->输入回车,以0.0.1为发布版本,也可以输入新的版本
###############################################################################
What is SCM release tag or label for "record Maven Webapp"? (com.gxx:record) rec
ord-0.0.1: :
###############################################################################
->输入回车,以record-0.0.1为tag标签名称,也可以输入新的标签
###############################################################################
What is the new development version for "record Maven Webapp"? (com.gxx:record)
0.0.2-SNAPSHOT: :
###############################################################################
->输入回车,以0.0.2-SNAPSHOT为新的开发版本,也可以输入新的版本
###############################################################################
...
[INFO] Release preparation complete.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 32.574s
[INFO] Finished at: Mon Jul 06 16:03:00 CST 2015
[INFO] Final Memory: 4M/8M
[INFO] ------------------------------------------------------------------------
###############################################################################
#这个时候在svn://121.43.104.34/gxx/tags/record下可以看到名字为record-0.0.1的tag
#pom.xml从0.0.1-SNAPSHOT变成0.0.2-SNAPSHOT,并提交svn
#record文件夹下会出现俩文件:pom.xml.releaseBackup和release.properties
D:\05.HeadWorkspace\record>mvn release:perform #再执行脚本
#maven-release-plugin会自动帮我们检出刚才打的tag,然后打包,分发到nexus私有仓库中
==== 结束检查 ====
查看pom.xml
{{ :分享:技术:maven:maven插件截图3.png?300 |}}
查看svn
{{ :分享:技术:maven:maven插件截图1.png?200 |}}
查看nexus
{{ :分享:技术:maven:maven插件截图2.png?300 |}}
==== 错误记录 ====
在这个过程中我报过一些错误,这里都记录了下来,如果有相同的错误信息出现,可以参考后面跟的解决方案
报错:
[ERROR] Command output:
[ERROR] 'svn' 不是内部或外部命令,也不是可运行的程序
[ERROR] 或批处理文件。
解决方法:
windows安装svn的时候默认是不安装 svn command line这个东西的,重新打开svn的安装exe,选择modify,将“command line client tools”允许安装,然后next继续安装(注意版本一致性)。
http://blog.csdn.net/mitea90/article/details/19075673
报错:
[ERROR] Command output:
[ERROR] svn: E155007: 'D:\05.HeadWorkspace\record\pom.xml' is not a working copy
解决方法:
项目必须是从svn仓库co出来的
报错:
[ERROR] svn: E155036: Please see the 'svn upgrade' command
[ERROR] svn: E155036: The working copy at 'D:\05.HeadWorkspace\record'
[ERROR] is too old (format 29) to work with client version '1.8.10 (r1615264)' (
expects format 31). You need to upgrade the working copy first.
解决方法:
对本地文件夹进行一次upgrade操作,在项目文件夹上右键,svn upgrade
报错:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4
:prepare (default-cli) on project record: Cannot prepare the release because you
have local modifications :
[ERROR] [pom.xml:modified]
[ERROR] [src\main\java\com\gxx\record\web\user\UserController.java:modified]
[ERROR] [src\main\webapp\WEB-INF\ftl\user\preRegist.ftl:deleted]
[ERROR] [src\main\webapp\WEB-INF\ftl\user\preRegistFtl.ftl:added]
解决方法:
由于要发布release版本,前提一定要代码先提交完,所以要先提交代码
报错:
[ERROR] The svn tag command failed.
[ERROR] Command output:
[ERROR] svn: E160013: File not found: transaction '6-6', path '/tags/record/reco
rd-0.0.1'
解决方法:
trunk,tags,branches需要import导入初始化资源,客户端才能读取和提交内容到该目录下