Introduction to maven?
Maven is basically a project management tool, where we manage our projects, we can build projects, deploy projects & many more features like reporting & documentation. It refers concept of Project Object Model (POM). In a short term, it is a build tool.
If you are using build tool like mavn, it simplifies your build process. everything becomes very simple because it follows some life-cycle what it has. we will talk about mavn life-cycle in couple of next para.
Why do we need maven project?
Earlier project who does not have mavn, they need to add jar files manually & if multiple persons are working on the same project, they have to use same jar files. If one has changed, it cause issues. Also earlier to mavn, we used to create project folder structure by our own. Where as after mavn, this is not manually required, because –
1. In case of maven project, you need not add any jar files in to the project. just add all your dependency in POM.xml file
2. Maven project creates a very good project folder structure for coding purpose.
So, in Short, Maven has two main purposes
- Project management (Includes creating folder structure, compiling, packaging etc.)
- Dependency management (update dependencies in POM.xml file to download jar automatically)
As i said earlier, maven is a build tool, now let us try and understand what us build tool.
Build tool has a set of processes, certain outcomes like compile source code, copying resources, compiling and running tests, packaging project(in jar or zip file based on selected option), deploying project & finally cleanup. So when you compile your source code using maven, it will create a jar or war file for further use.
All settings of maven project are POM.xml file
What is POM.xml?
POM is an xml file that contain an information about project and configuration details used by mavn to build project. Information is about name, version, artifact it, dependencies, plugin information & profiles. We will talk about POM.xml in more details in coming sessions.
What are important maven objectives?
- Making the build process easy.
- Provides the uniform build system.
- Provide quality project information.
- Providing guidelines for best practices development.
- Allowing transparent migration to new feature.]
Maven Build Lifecycle –
For the person building a project, this means that it is only necessary to learn a small set of commands to build any Maven project, and the POM will ensure they get the results they desired.
There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project’s site documentation.
Each of these build lifecycles is defined by a different list of build phases, wherein a build phase represents a stage in the lifecycle.
For example, the default lifecycle comprises of the following phases (for a complete list of the lifecycle phases, refer to the Lifecycle Reference):
- validate – validate the project is correct and all necessary information is available
- compile – compile the source code of the project
- test – test the compiled source code using a suitable unit testing framework. These tests should not require the code be package or deploy.
- package – take the compiled code and package it in its distributable format, such as a JAR.
- verify – run any checks on results of integration tests to ensure quality criteria are met
- install – install the package into the local repository, for use as a dependency in other projects locally
- deploy – done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.
These lifecycle phases (plus the other lifecycle phases not shown here) are executed sequentially to complete the default lifecycle. Given the lifecycle phases above, this means that when the default lifecycle is used, Maven will first validate the project, then will try to compile the sources, run those against the tests, package the binaries (e.g. jar), run integration tests against that package, verify the integration tests, install the verified package to the local repository, then deploy the installed package to a remote repository.
I will talk about maven in more detail in next articles. Refer below links –