English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Maven Automated Build

Automated build defines such a scenario: after a project is successfully built, its related dependent projects start to build, which can ensure the stability of its dependent projects.

For example, a team is developing a project bus-core-api, and there are other two projects app-web-ui and app-desktop-The ui depends on this project.

app-web-The ui project uses the bus-core-The api project 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-web-ui</groupId>
   <artifactId>app-web-ui</artifactId>
   <version>1.0</version>
   <packaging>jar</packaging>
   <dependencies>
      <dependency>
      <groupId>bus-core-api</groupId>
         <artifactId>bus-core-api</artifactId>
         <version>1.0-SNAPSHOT</version>
      </dependency>
   </dependencies>
</project>

app-desktop-The ui project uses the bus-core-The api project 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-desktop-ui</groupId>
   <artifactId>app-desktop-ui</artifactId>
   <version>1.0</version>
   <packaging>jar</packaging>
   <dependencies>
      <dependency>
      <groupId>bus-core-api</groupId>
         <artifactId>bus-core-api</artifactId>
         <version>1.0-SNAPSHOT</version>
      </dependency>
   </dependencies>
</project>

bus-core-Api project:

<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>bus-core-api</groupId>
   <artifactId>bus-core-api</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>jar</packaging>   
</project>

Now the app-web-ui and app-desktop-The ui project team requires that regardless of the bus-core-When the api project changes, their build process should also be able to start.

Using snapshots can ensure the latest bus-core-The api project is used, but to meet the above requirements, we still need to do some additional work.

There are two ways to use:

  • in the bus-core-add a post in the pom file of the api project-build the target operation to start the app-web-ui and app-desktop-The build of the ui project.

  • Use a continuous integration (CI) server, such as Hudson, to manage build automation manually.

Use Maven

Modify bus-core-The pom.xml file of the api project.

<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>bus-core-api</groupId>
   <artifactId>bus-core-api</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>jar</packaging>
   <build>
   <plugins>
   <plugin>
      <artifactId>maven-invoker-plugin</artifactId>
      <version>1.6</version>
      <configuration>
         <debug>true</debug>
         <pomIncludes>
            <pomInclude>app-web-ui/pom.xml</pomInclude>
            <pomInclude>app-desktop-ui/pom.xml</pomInclude> 
         </pomIncludes>
      </configuration>
      <executions>
         <execution>
            <id>build</id>
            <goals>
               <goal>run</goal>
            </goals>
         </execution>
      </executions>
   </plugin>
   </plugins>
   </build>
</project>

Open the command console, switch to C:\ > MVN > bus-core-Under the api directory, then execute the following command.

C:\MVN\bus-core-api>mvn clean package -U

After executing the command, Maven will start building the project bus-core-api.

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------
[INFO] Building bus-core-api
[INFO] task-segment: [clean, package]
[INFO] ------------------------------------------------------------------
...
[INFO] [jar:jar {execution: default-}
[INFO] Building jar: C:\MVN\bus-core-ui\target\
bus-core-ui-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------

bus-core-After the api build is successful, Maven will start building the app-web-ui project.

[INFO] ------------------------------------------------------------------
[INFO] Building app-web-ui 
[INFO] task-segment: [package]
[INFO] ------------------------------------------------------------------
...
[INFO] [jar:jar {execution: default-}
[INFO] Building jar: C:\MVN\app-web-ui\target\
app-web-ui-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------

app-web-After the ui build is successful, Maven will start building the app-desktop-ui project.

[INFO] ------------------------------------------------------------------
[INFO] Building app-desktop-ui 
[INFO] task-segment: [package]
[INFO] ------------------------------------------------------------------
...
[INFO] [jar:jar {execution: default-}
[INFO] Building jar: C:\MVN\app-desktop-ui\target\
app-desktop-ui-1.0-SNAPSHOT.jar
[INFO] -------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] -------------------------------------------------------------------

Using Continuous Integration Server (CI)

If using a CI server, every new project, such as the app in the example, is-mobile-ui, add as a dependency to bus-core-when developing the api project, developers do not need to update bus-core-pom of the api project. Hudson will use Maven's dependency management feature to automate the creation of the project.

Hudson treats each project build as a task. After the code of a project is committed to SVN (or any code management tool mapped to Hudson), Hudson will start the project build task, and once this build task is completed, Hudson will automatically start other dependent build tasks (builds of other dependent projects).

In the above example, when bus-core-After the SVN update of the ui source code, Hudson starts the project build. Once the build is successful, Hudson automatically searches for dependent projects and then starts building the app-web-ui and app-desktop-ui project.