Maven - Maven Build Automation - maven tutorial
What is Build Automation?
- 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.
- Below mentioned are the pom.xml files for two dependent projects.
maven tutorial tags : apache maven , maven repository , maven central
CoreJavawikitechy Project:
JavaSamples Project:
- 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.
- Post build goal is nothing but, a goal which defines a specific set of tasks once the build is successful. e.g. generating javadocs is a post build goal.
Sample Code:
Build Automation using Jenkins Server:
- Jenkins Server is a continuous integration tool.
- Using Jenkins build can be automated, tested for the health status of the builds and also multiple builds can be managed.
- It is a handy tool which is easily available to download and very easy to set up.
Setting up Jenkins Server
- Download the latest Jenkins.war from following link
learn maven tutorial - maven setting up jenkins server - maven example
- Deploy the Jenkins.war file in the local web server of our machine. E.g. Tomcat
- Start the server and open the browser and hit
learn maven tutorial - maven automation server - maven example
Creating a new Job and Deploying the Build
- Click on the Create new jobs link, shown in picture above, to configure a project for build automation. Enter the details of the project as shown below and click OK.
- You must enter the Name and select the radio button for Maven Project.
learn maven tutorial - maven new bulid - maven example
- In the next page, fill all the required details like - Description, Path of the project's pom.xml and other details and click save.
- Please check the below picture for help. Fill all the information and click on SAVE
learn maven tutorial - maven textbulid save - maven example
learn maven tutorial - maven fil -automation - maven example
learn maven tutorial - maven fill information click save - learn maven tutorial
- A Project/Job is now created in Jenkins. As shown below :
learn maven tutorial - created jenkins buildnow in maven - maven example
learn maven tutorial - maven jenkins build-history - maven example
- Click on the build number link and it opens up the build details. Click on the Console Output to see the logs of the build.
learn maven tutorial - jenkins module build in maven - maven example
learn maven tutorial - maven jenkins check the logs - maven example
learn maven tutorial - meaven build - maven example