Maven - SPLessons

Maven Build Automation

Home > Lesson > Chapter 12
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Maven Build Automation

Maven Build Automation

shape Introduction

The process of updating the build process while making changes in the work-space is known as Maven Build Automation. It also checks whether the project is undisturbed after making the changes. The checking process is required because with failed builds, it is really hard to manage a project.

shape Conceptual figure

shape Description

For example, consider JavaSamples project as a dependent project of SPlessons project. Maven can compile every class under every package independently. Splessons.xml [xml] <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>Splessons</groupId> <artifactId>Splessons</artifactId> <version>1.0</version> <packaging>jar</packaging> <dependencies> <dependency> <groupId>JavaSamples</groupId> <artifactId>JavaSamples</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </project>[/xml] JavaSamples.xml [xml]<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>JavaSamples</groupId> <artifactId>JavaSamples</artifactId> <version>1.0</version> <packaging>jar</packaging> </project> [/xml] Changes can be made to the JavaSamples project by adding post-build goal after successful completion. [xml] <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>JavaSamples</groupId> <artifactId>JavaSamples</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <build> <plugins> <plugin> <artifactId>maven-invoker-plugin</artifactId> <version>1.6</version> <executions> <execution> <id>build</id> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> <build> </project> [/xml] Now, enter the mvn verify command. The project will be updated with given changes.

Summary

shape Key Points

  • Maven Build Automation updates projects when the changes are being made.
  • Post-build goal is one process to build automate.