大型軟件應(yīng)用程序通常由多個(gè)模塊組成,這是多個(gè)團(tuán)隊(duì)工作于同一應(yīng)用程序的不同模塊的常見場(chǎng)景。例如一個(gè)團(tuán)隊(duì)工作負(fù)責(zé)應(yīng)用程序的前端應(yīng)用用戶接口工程(app-ui.jar:1.0)),同時(shí)他們使用數(shù)據(jù)服務(wù)工程(data-service.jar:1.0)。
現(xiàn)在負(fù)責(zé)數(shù)據(jù)服務(wù)的團(tuán)隊(duì)可能正在進(jìn)行修正 bug 或者增強(qiáng)功能,并快速迭代,然后他們幾乎每天都會(huì) release 工程庫文件到遠(yuǎn)程倉庫中。
現(xiàn)在如果數(shù)據(jù)服務(wù)團(tuán)隊(duì)每天上傳新的版本,那么就會(huì)有下面的問題:
為了解決這樣的情況,快照概念發(fā)揮了作用.
快照是一個(gè)特殊的版本,它表示當(dāng)前開發(fā)的一個(gè)副本。與常規(guī)版本不同,Maven 為每一次構(gòu)建從遠(yuǎn)程倉庫中檢出一份新的快照版本。
現(xiàn)在數(shù)據(jù)服務(wù)團(tuán)隊(duì)會(huì)將每次更新的代碼的快照(例如 data-service:1.0-SNAPSHOT)發(fā)布到倉庫中,來替換舊的快照 jar 文件。
對(duì)于版本,Maven 一旦下載了指定的版本(例如 data-service:1.0),它將不會(huì)嘗試從倉庫里再次下載一個(gè)新的 1.0 版本。想要下載新的代碼,數(shù)據(jù)服務(wù)版本需要被升級(jí)到 1.1。
對(duì)于快照,每次用戶接口團(tuán)隊(duì)構(gòu)建他們的項(xiàng)目時(shí),Maven 將自動(dòng)獲取最新的快照(data-service:1.0-SNAPSHOT)。
應(yīng)用用戶接口工程正在使用 1.0 版本的數(shù)據(jù)服務(wù)的快照
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>app-ui</groupId>
<artifactId>app-ui</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>health</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>data-service</groupId>
<artifactId>data-service</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
數(shù)據(jù)服務(wù)工程為每個(gè)微小的變化 release 1.0 快照
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>data-service</groupId>
<artifactId>data-service</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>health</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
雖然,對(duì)于快照,Maven 每次自動(dòng)獲取最新的快照,但你可以在任何 maven 命令中使用 -U 參數(shù)強(qiáng)制 maven 下載最新的快照。
mvn clean package -U
讓我們打開命令控制臺(tái),進(jìn)入 C:\ > MVN > app-ui 目錄并執(zhí)行以下 mvn 命令。
C:\MVN\app-ui>mvn clean package -U
Maven將在下載數(shù)據(jù)服務(wù)的最新快照后,開始構(gòu)建工程。
[INFO] Scanning for projects...
[INFO] -------------------------------------------------------------------
[INFO] Building consumerBanking
[INFO] task-segment: [clean, package]
[INFO] -------------------------------------------------------------------
[INFO] Downloading data-service:1.0-SNAPSHOT
[INFO] 290K downloaded.
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory C:\MVN\app-ui\target
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\MVN\app-ui\src\main\
resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to C:\MVN\app-ui\target\classes
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\MVN\app-ui\src\test\
resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 1 source file to C:\MVN\app-ui\target\test-classes
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\MVN\app-ui\target\
surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.companyname.bank.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.027 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] [jar:jar {execution: default-jar}]
[INFO] Building jar: C:\MVN\app-ui\target\
app-ui-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Jul 10 16:52:18 IST 2012
[INFO] Final Memory: 16M/89M
[INFO] ------------------------------------------------------------------------
更多建議: