Previous – Chapter 10

Maven Tutorial – Chapter 11

In the previous chapter, we learnt on how to manage the external dependencies for a project. Now, we will see on how to automate a build process using maven.

Maven Build Automation

Maven Build automation is the process in which a project gets initiated with the build process whenever a change is made in the workspace and also to ensure that project is stable along with its dependent projects (if the project is used by any other projects).

This is very much essential in the software development life cycle as it is difficult to manage with the failed builds during the development phase. Hence, a process is required in order to ensure the health status of the build all the time and keep an eye on the same.

Consider the project “JavaSamples” in this scenario. Here, lot of programs varying across different oops concept will be written and tested. But, it is always difficult to test every class independently for the compilation issue since they are modularized under different set of packages. In order to achieve this, maven provides a feature to automate the same. Consider, developers want to check the build stability after each check in done to the project. Also, consider that this JavaSamples project is a dependent project of another project called “CoreJavaTutorials”. Hence, it is mandatory to maintain a stable build of JavaSamples.

CoreJavaTutorials project

[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>CoreJavaTutorials</groupId>
<artifactId>CoreJavaTutorials </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 Project

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

Now consider that there are some changes made on the JavaSamples project. Developer need to update the pom.xml of the JavaSamples project by adding a post build goal on the same.

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

Also, Jenkins server can be used to manage the build automation.

jenkins_1
jenkins_2jenkins_3Next – Chapter 12

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *