English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Une grande application logicielle contient généralement plusieurs modules, et dans de nombreux cas, plusieurs équipes développent des modules différents de la même application. Prenez un exemple, imaginez une équipe développant l'avant du projet, le projet est app-ui(app-ui.jar :10), tandis qu'une autre équipe développe le backend de l'application, utilisant le projet data-service(data-service.jar :10).
Il se peut que le développement de data-L'équipe service travaille à un rythme rapide pour corriger les bugs ou améliorer le projet, et ils doivent presque publier des bibliothèques sur des dépôts distants tous les deux jours. Actuellement, si data-Si l'équipe service télécharge une nouvelle version tous les deux jours, des problèmes suivants peuvent apparaître :
data-L'équipe service doit informer l'application chaque fois qu'elle publie des codes mis à jour.-L'équipe UI.
app-L'équipe UI doit souvent mettre à jour leur fichier pom.xml à la dernière version.
To solve this situation,SnapshotThe concept comes into play.
Snapshot is a special version that specifies a copy of the current development progress. Unlike regular versions, Maven checks for new snapshots in the remote repository every time it builds. Now data-The service team will release the snapshot of the updated code to the repository every time, such as data-service:1.0-SNAPSHOT instead of the old snapshot jar package.
For versions, if Maven has previously downloaded the specified version file, such as data-service:1.0, Maven will no longer download new available 1.0 file. To download the updated code, data-The version of service needs to be upgraded to1.1.
In the case of snapshot, each app-When the ui team builds their project, Maven will automatically retrieve the latest snapshot (data-service:1.0-SNAPSHOT).
app-The ui project uses data-The service project's 1.0 Snapshot.
<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>
data-The service project is released for each small change 1.0 Snapshot.
<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>
虽然,快照的情况下,Maven 在日常工作中会自动获取最新的快照, 你也可以在任何 maven 命令中使用 -U 参数强制 maven 现在最新的快照构建。
mvn clean package -U
让我们打开命令控制台,去到 C:\ > MVN > app-ui 目录,然后执行下面的 mvn 命令。
C:\MVN\app-ui>mvn clean package -U
Maven 将在下载 data-service 最新 的 快照 之后,开始构建项目。
[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\ ressources [INFO] [compiler:compile {execution: default-compile}] [INFO] Compilation 1 fichier source à 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\ ressources [INFO] [compiler:testCompile {execution: default-testCompile}] [INFO] Compilation 1 fichier source à C:\MVN\app-ui\target\test-classes [INFO] [surefire:test {execution: default-test}] [INFO] Répertoire de rapport Surefire : C:\MVN\app-ui\target\ surefire-rapports ------------------------------------------------------- TÉS T S ------------------------------------------------------- Exécution de com.companyname.bank.AppTest Tests exécutés : 1, Échecs: 0, Erreurs: 0, Ignorés: 0, Temps écoulé: 0.027 sec Résultats : Tests exécutés : 1, Échecs: 0, Erreurs: 0, Ignorés: 0 [INFO] [jar:jar {execution: default-jar}] [INFO] Construction de jar : C:\MVN\app-ui\target\ app-ui-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] CONSTRUCTION REUSSIE [INFO] ------------------------------------------------------------------------ [INFO] Temps total : 2 secondes [INFO] Terminé à : Mar Mer 10 16:52:18 IST 2012 [INFO] Mémoire finale : 16M/89M [INFO] ------------------------------------------------------------------------