通常在Nightly Build的環節,我比較喜歡Clean Build,也就是從Checkout、Compile、Test、Deploy都是一個動作完成的Compile、Test、Deploy都可以靠Maven或Ant完成,但是自VCS中checkout source code就要看plugin的支援程度了。即便是plugin支援度不夠,只要該種VCS有提供command line的模式,我想就能利用shell或script的方式來達到完整的Clean Build。 例如:
git clone [url] #checkout source code from VCS
cd [project]
mvn site -Pprod
當然利用Maven提供的SCM來處理也是不錯,除了checkin, checkout之外也可以利用scm plugin來列出changelog或add、remove檔案,不過我個人是比較少用到這些功能就是。
Maven提供的SCM Plugin請參考 http://maven.apache.org/scm/plugins/index.html, 而支援的SCM的完整度則可以考http://maven.apache.org/scm/matrix.html
Maven提供的SCM Plugin請參考 http://maven.apache.org/scm/plugins/index.html, 而支援的SCM的完整度則可以考http://maven.apache.org/scm/matrix.html
為了使用Maven的SCM Plugin,通常單獨將<scm>建一個pom.xml,其他plugin或build的東西就免寫了,當然要用原來project的pom.xml也無不可,簡單看個例子。
<project xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"> <modelversion>4.0.0</modelversion> <groupid>idv.elliot</groupid> <artifactid>BuildDemo</artifactid> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>BuildDemo</name> <url>http://github.com/ElliotChen/BuildDemo </url> <scm> <!-- 僅供讀取的Connection URL, 前面必需加上scm:xxx --> <connection>scm:git:git://github.com/ElliotChen/BuildDemo.git </connection> <!-- 可以執行checkin的Connection URL, 前面必需加上scm:xxx --> <developerconnection>scm:git:git://github.com/ElliotChen/BuildDemo.git </developerconnection> <url>http://github.com/ElliotChen/BuildDemo </url> </scm> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-scm-plugin</artifactid> <version>1.3</version> <!-- Checkout之後要執行的Goal --> <configuration> <goals>site</goals> </configuration> </plugin> </plugins> </build> </project>
簡單來說,只要在<scm>裡的<connection>填入SCM checkout source code的url,然後在url之前依你使用的SCM種類加上指定的prefix,然後在<maven-scm-plugin>的<configuration>中填上接下來要執行的goal,最後執行
mvn clean scm:bootstrap這樣就可以看到像下列的輸出:
[INFO] [scm:bootstrap {execution: default-cli}] [INFO] Removing /Users/elliot/tmp/target/checkout [INFO] Executing: /bin/sh -c cd /Users/elliot/tmp/target && git clone git://github.com/ElliotChen/BuildDemo.git /Users/elliot/tmp/target/checkout [INFO] Working directory: /Users/elliot/tmp/target [INFO] Executing: /bin/sh -c cd /Users/elliot/tmp/target/checkout && git pull git://github.com/ElliotChen/BuildDemo.git master [INFO] Working directory: /Users/elliot/tmp/target/checkout [INFO] Executing: /bin/sh -c cd /Users/elliot/tmp/target/checkout && git checkout [INFO] Working directory: /Users/elliot/tmp/target/checkout [INFO] Executing: /bin/sh -c cd /Users/elliot/tmp/target/checkout && git ls-files [INFO] Working directory: /Users/elliot/tmp/target/checkout [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building BuildDemo [INFO] task-segment: [site] [INFO] ------------------------------------------------------------------------ [INFO] [site:site {execution: default-site}]
沒有留言:
張貼留言