Build Automation in Maven

Build Automation in Maven

Build Automation describes the scenario in which the build process for the dependent project(s) begins once the project build is done successfully to verify that the dependent project(s) is/are stable.


Consider a team working on the bus-core-API project, which is dependent on the app-web-UI and app-desktop-UI projects.

The bus-core-API project uses 1.0-SNAPSHOT for the app-web-UI project.

<project xmlns = "" xmlns:xsi = "" xsi:schemaLocation = ""> <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 bus-core-api project uses 1.0-SNAPSHOT for the app-desktop-ui project.

<project xmlns = "" xmlns:xsi = "" xsi:schemaLocation = ""> <modelVersion>4.0.0</modelVersion> <groupId>app_desktop_ui</groupId> <artifactId>app_desktop_ui</artifactId> <version>1.0</version> <packaging>jar</packaging> <name>app_desktop_ui</name> <url></url> <properties> <>UTF-8</> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>bus_core_api</groupId> <artifactId>bus_core_api</artifactId> <version>1.0-SNAPSHOT</version> <scope>system</scope> <systemPath> C:\MVN\bus_core_api\target\bus_core_api-1.0-SNAPSHOT.jar </systemPath> </dependency> </dependencies> </project>

bus-core-api project −

<project xmlns = "" xmlns:xsi = "" xsi:schemaLocation = ""> <modelVersion>4.0.0</modelVersion> <groupId>bus_core_api</groupId> <artifactId>bus_core_api</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> </project>

Teams working on the app-web-UI and app-desktop-UI projects now have to restart their build processes anytime the bus-core-API project changes.
Using a snapshot assures that the most recent bus-core-API project is used, but we must do something additional to meet the above criterion.

We have two options for moving forward. −

Add a post-build objective to start the app-web-UI and app-desktop-UI pom in the bus-core-API pom.

Update the pom.xml file for the bus-core-API project with Maven.

<project xmlns = "" xmlns:xsi = "" xsi:schemaLocation = ""> <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>

To begin, open a command prompt, navigate to the C: > MVN > bus-core-API directory, and run the following mvn command: >mvn clean package -U

Maven will begin working on the bus-core-API project.

[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] -----------------------------