What is Maven?
•Maven is a powerful project management tool that is based on POM (project object model).
•It is used for project build, dependency, and documentation.
•It simplifies the build process like ANT. But it is too much advanced than ANT.
- In short terms we can tell maven is a tool that can be used for building and managing any Java-based project. maven make the day-to-day work of Java developers easier and generally help with the comprehension of any Java-based project.
What maven does?
Maven does a lot of helpful tasks like
•We can easily build a project using maven.
•We can add jars and other dependencies of the project easily using the help of maven.
•Maven provides project information (log document, dependency list, unit test reports, etc.)
•Maven is very helpful for a project while updating the central repository of JARs and other dependencies.
•With the help of Maven we can build any number of projects into output types like the JAR, WAR, etc. without doing any scripting.
- Using maven we can easily integrate our project with a source control system (such as Subversion or Git).
Maven Build Lifecycle:
Default->Clean -> site ->
Maven Lifecycle Phases
•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 to be packaged or deployed
•package — take the compiled code and package it in its distributable format, such as a JAR.
•Integration test: It runs the integration tests for the project.
•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 built environment, copies the final package to the remote repository for sharing with other developers and projects.
Clean Clean up after the build.
compiler Compiles Java sources.
deploy Deploy the built artifact to the remote repository.
failsafe Run the JUnit integration tests in an isolated class loader.
install Install the built artifact into the local repository.
resources Copy the resources to the output directory for including in the JAR.
site Generate a site for the current project.
surefire Run the JUnit unit tests in an isolated class loader.
verifier Useful for integration tests — verifies the existence of certain conditions.
Basic Maven Commands:
•mvn clean: Cleans the project and removes all files generated by the previous build.
•mvn compile: Compiles source code of the project.
•mvn test-compile: Compiles the test source code.
•mvn test: Runs tests for the project.
•mvn package: Creates JAR or WAR file for the project to convert it into a distributable format.
•mvn install: Deploys the packaged JAR/ WAR file to the local repository.
- mvn deploy: Copies the packaged JAR/ WAR file to the remote repository after compiling, running tests, and building the project
Bharathi Balaji Rangaraj - Test Automation Engineer - iInterchange Systems Private Limited |…
Senior Software Testing Engineer with 10 years of experience in Information Technology with specialization in Software…