Maven — Architecture and Life Cycle
In our Automation project, we are using a key tool that makes our framework feasible and manageable. That saviour tool is MAVEN.
Let’s understand what is Maven and how it works.
What is Maven?
In simple terms, Maven is a build automation tool that generates a build for you.
Problem: I am using the following technologies in my project:
- JDK 11 ~ Java
- Selenium WebDriver
- TestNG/JUnit
- Apache POI API
- Log4J API
- JSON/GSON
few other technologies as per the requirement…
There is a hectic process to download JARs for each technology and add them to a project. What if any of the jars got missed? How do I be able to debug which jar is missing out of hundreds of jars?
Doesn’t it sound scary? 😱
Solution: What if I tell you there is no need to beat your brain🤕!! There is an easy solution to this tricky problem.
Let’s have a look at the diagram below:
In Maven Repository, all the jar files are available in the form of dependencies. The jars which are required in a project can be taken from Maven Centralised Repository.
Format of a dependency:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
<scope>test</scope>
</dependency>
Maven repository is like a library of all open source technologies.
Once you add the dependencies in your project (pom.xml), it will load all jar files and store them in a .m2 folder in your eclipse. This is a hidden folder.
Maven Life Cycle
The Maven life cycle consists of 8 phases. It will compile, test, build and install a project as specified below:
- Validate: This step checks if the project structure is correct. It checks whether all the dependencies have been downloaded and are available in the local repository.
- Compile: It compiles the source code, converts the .java files to .class and stores the classes in the target/classes folder.
- Test: It executes unit tests for the project.
- Package: This step packages the compiled code in a distributable format such as JAR/WAR or EAR.
- Integration test: Conducts Integration testing for the project by executing Intergration tests.
- Verify: This step runs to ensure that the project meets the quality standards.
- Install: This step installs the packaged code into the local Maven repository.
- Deploy: It copies the packaged code to the remote repository.
Hope this helps you to understand the basics of Maven.
Thanks for reading 🙏🏻 📄