首页 > 代码库 > maven项目管理
maven项目管理
1、添加SCM
首先我们需要在POM中加入scm信息,这样Maven才能够替你完成svn操作,这里我的配置如下:
Xml代码 :
2、配置maven-release-plugin
这个插件会帮助我们升级pom版本,提交,打tag,然后再升级版本,再提交,等等。基本配置如下:
xml代码 :
这里我们需要注意的是configuration元素下的tagBase元素,它代表了我们svn中的tag目录,也就是说,maven-release-plugin帮我们打tag的时候,其基础目录是什么。
3、注意事项
确保你的所有代码都提交了,如果你有未提交代码,release插件会报错,既然你要发布版本了,就表示代码是稳定的,所以要么要么把代码提交了,要么把本地的更改抛弃了。
4、开始执行第一个命令
D:\workspace\webapp>mvn release:prepare
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building webappName Maven Webapp 1.6-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.0-beta-7:prepare (default-cli) @ webappName --
-
[INFO] Release preparation already completed. You can now continue with release:
perform, or start again using the -Dresume=false flag
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.860 s
[INFO] Finished at: 2014-11-09T22:53:30+08:00
[INFO] Final Memory: 2M/5M
[INFO] ------------------------------------------------------------------------
上面信息可以看出我当前的版本为1.6-SNAPSHOT,并且版本的准备已经完成。
并且还提示我,接下来可以继续执行的命令为:
release:perform (进行项目的发布) 或者 重新再来准备一次使用-Dresume=false
发布先不管,运行
D:\workspace\webapp>mvn release:prepare -Dresume=false
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building webappName Maven Webapp 1.6-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.0-beta-7:prepare (default-cli) @ webappName --
-
[INFO] Verifying that there are no local modifications...
[INFO] Executing: svn --non-interactive status
[INFO] Working directory: D:\workspace\webapp
[INFO] Checking dependencies and plugins for snapshots ...
What is the release version for "webappName Maven Webapp"? (packageName:webappNa
me) 1.6: :
你想将1.6-SNAPSHOT发布为什么版本?默认是1.6。”我要的就是1.6,直接回车。
What is SCM release tag or label for "webappName Maven Webapp"? (packageName:web
appName) webappName-1.6: :
发布的tag标签名称是什么?默认为webappName-1.6。”我还是要默认值,直接回车。
What is the new development version for "webappName Maven Webapp"? (packageName:
webappName) 1.7-SNAPSHOT: :
主干上新的版本是什么?默认为1.7-SNAPSHOT。”哈,release插件会自动帮我更新版本到1.7-SNAPSHOT,很好,直接回车。
[INFO] Transforming ‘webappName Maven Webapp‘...
[INFO] Not generating release POMs
[INFO] Executing goals ‘clean verify‘...
[INFO] Executing: mvn clean verify --no-plugin-updates -P center
[WARNING] Command line option -npu is deprecated and will be removed in future M
aven versions.
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------------------------------------------------
-------
[INFO] Building webappName Maven Webapp 1.6
[INFO] -----------------------------------------------------------------
-------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ webappName ---
[INFO] Deleting D:\workspace\webapp\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ we
bappName ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resour
ces, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ webappN
ame ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResourc
es) @ webappName ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resour
ces, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\workspace\webapp\src\test\
resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @
webappName ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ webappName
---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ webappName ---
[INFO] Packaging webapp
[INFO] Assembling webapp [webappName] in [D:\workspace\webapp\target\web
appName]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\workspace\webapp\src\main\webapp]
[INFO] Webapp assembled in [44 msecs]
[INFO] Building war: D:\workspace\webapp\target\webappName.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] -----------------------------------------------------------------
-------
[INFO] BUILD SUCCESS
[INFO] -----------------------------------------------------------------
-------
[INFO] Total time: 2.754 s
[INFO] Finished at: 2014-11-09T23:04:31+08:00
[INFO] Final Memory: 4M/9M
[INFO] -----------------------------------------------------------------
-------
[INFO] Checking in modified POMs...
[INFO] Executing: svn --non-interactive commit --file C:\Users\ADMINI~1\AppData\
Local\Temp\maven-scm-375208472.commit --targets C:\Users\ADMINI~1\AppData\Local\
Temp\maven-scm-5511113549166271924-targets
[INFO] Working directory: D:\workspace\webapp
[INFO] Tagging release with the label webappName-1.6...
[INFO] Executing: svn --non-interactive copy --file C:\Users\ADMINI~1\AppData\Lo
cal\Temp\maven-scm-258074596.commit . http://WOP8UNUZM6ZBE4H/svn/webapp/tags/web
appName-1.6
[INFO] Working directory: D:\workspace\webapp
[INFO] Transforming ‘webappName Maven Webapp‘...
[INFO] Not removing release POMs
[INFO] Checking in modified POMs...
[INFO] Executing: svn --non-interactive commit --file C:\Users\ADMINI~1\AppData\
Local\Temp\maven-scm-1222592472.commit --targets C:\Users\ADMINI~1\AppData\Local
\Temp\maven-scm-2494449146640843872-targets
[INFO] Working directory: D:\workspace\webapp
[INFO] Release preparation complete.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:34 min
[INFO] Finished at: 2014-11-09T23:04:34+08:00
[INFO] Final Memory: 2M/5M
[INFO] ------------------------------------------------------------------------
执行成功后pom配置从原来的1.6版本被更新到了1.7
svn服务器上tag添加了1.6版本的信息
项目根目录生成了2新文件
pom.xml.releaseBackup 原来pom文件的备份(版本回滚需要)
release.properties前后两版本的关联信息(版本回滚需要)
5、发布准备 批量模式执行
还是之前的那个命令就添加2参数
D:\workspace\webapp>mvn --batch-mode release:prepare -Dresume=false
6、项目回滚
前提条件:上一次发布到这次回滚之间没有执行过
mvn release:clean
这个命令。因为这个命令会把前面提到的2文件删除,导致无法回滚
pom.xml.releaseBackup 原来pom文件的备份(版本回滚需要)
release.properties前后两版本的关联信息(版本回滚需要)
回滚命令
mvn release:rollback
D:\workspace\webapp>mvn release:rollback
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building webappName Maven Webapp 1.8.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.0-beta-7:rollback (default-cli) @ webappName
--
[INFO] Checking in modified POMs...
[INFO] Executing: svn --non-interactive commit --file C:\Users\ADMINI~1\AppData
Local\Temp\maven-scm-1383801082.commit --targets C:\Users\ADMINI~1\AppData\Loca
\Temp\maven-scm-3876567308953457412-targets
[INFO] Working directory: D:\workspace\webapp
[INFO] Cleaning up after release...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.453 s
[INFO] Finished at: 2014-11-09T23:46:03+08:00
[INFO] Final Memory: 3M/6M
[INFO] ------------------------------------------------------------------------
回滚后版本号从原来的
1.8.2-SNAPSHOT
变成现在的:
而且根路径下的2文件被删除
pom.xml.releaseBackup 原来pom文件的备份(版本回滚需要)
release.properties前后两版本的关联信息(版本回滚需要)
在看一下svn服务器tag目录
1.8.1版本还在,说明回滚的时候只是项目中的版本回滚了,但是之前的打的tag没有被删除。。。。
我们可以看到回滚的局限性:
1、只能回滚到上一个版本
2、tag没被删除,需要自己手动的删除
http://maven.apache.org/maven-release/maven-release-plugin/examples/prepare-release.html
http://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html
执行mvn --batch-mode release:prepare -Dresume=false 前必须先执行
mvn --batch-mode release:prepare
执行
mvn --batch-mode release:prepare前必须先执行
mvn release:rollback
maven项目管理