11.14. Automatic construction of Maven

发布时间 :2025-10-25 12:23:15 UTC      

An automated build defines a scenario in which, after a project is successfully built, its related dependency project begins to build, which ensures the stability of its dependent project.

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

The app-web-ui project uses a 1.0 snapshot of the bus-core-api project:

<projectxmlns="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>

The app-desktop-ui project uses a 1.0 snapshot of the bus-core-api project:

<projectxmlns="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:

<projectxmlns="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-ui project teams require that their build process be able to start whenever the bus-core-api project changes.

Using snapshots ensures that the latest bus-core-api projects are used, but we need to do some extra work to meet the above requirements.

There are two ways to do this:

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

  • Use a continuous integration (CI) server, such as Hudson, to automate the build from line management.

11.14.1. Use Maven

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

<projectxmlns="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, change to the C:> MVN > bus-core-api directory, and execute the following command.

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

After executing the command, Maven starts 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-jar}]
[INFO] Building jar: C:\MVN\bus-core-ui\target\
bus-core-ui-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------

After the bus-core-api is built successfully, 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-jar}]
[INFO] Building jar: C:\MVN\app-web-ui\target\
app-web-ui-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------

After the app-web-ui is built successfully, 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-jar}]
[INFO] Building jar: C:\MVN\app-desktop-ui\target\
app-desktop-ui-1.0-SNAPSHOT.jar
[INFO] -------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] -------------------------------------------------------------------

11.14.2. Use continuous Integration Server (CI)

If you use the CI server, developers do not need to update the pom of the bus-core-api project each time a new project, such as app-mobile-ui in the instance, is added as a dependent bus-core-api project. Hudson will make use of the dependency management function of Maven to automate the creation of the project.

image0

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

In the above example, when the bus-core-ui source code is updated in SVN, Hudson starts building the project. Once the build is successful, Hudson automatically finds the dependent projects and then starts building the app-web-ui and app-desktop-ui projects.

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.