一、添加SCMhtml
首先咱們須要在POM中加入scm信息,這樣Maven纔可以替你完成svn操做,這裏個人配置以下:web
Xml代碼 :apache
二、配置maven-release-plugin服務器
這個插件會幫助咱們升級pom版本,提交,打tag,而後再升級版本,再提交,等等。基本配置以下:app
xml代碼 :webapp
這裏咱們須要注意的是configuration元素下的tagBase元素,它表明了咱們svn中的tag目錄,也就是說,maven-release-plugin幫咱們打tag的時候,其基礎目錄是什麼。maven
三、注意事項svn
四、開始執行第一個命令ui
D:\workspace\webapp>mvn release:preparespa
[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先後兩版本的關聯信息(版本回滾須要)
五、發佈準備 批量模式執行
仍是以前的那個命令就添加2參數
D:\workspace\webapp>mvn --batch-mode release:prepare -Dresume=false
六、項目回滾
前提條件:上一次發佈到此次回滾之間沒有執行過
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沒有被刪除。。。。
咱們能夠看到回滾的侷限性:
一、只能回滾到上一個版本
二、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