- What is maven?
- Maven is a build automation tool
- Maven can be used to build and manage projects created from Java, C#, Ruby etc…
- Maven can build, publish, and deploy several projects at once
- Maven focus on following things
- Build
- Documentation
- Dependencies
- Reports
- Releases
- Mailing list
- Maven is a build/project management tool, based on the concept of a project object model (POM) contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc.
What are the features of Maven?
- The ability to set up projects easily
- Dependency management
- Strong error and integrity reporting
- Automatic parent versioning
- Help to create the right project structure
How to install Maven?
- Download Maven from the Apache site
- Extract the zip file and locate it in a folder in your machine Ex: c:\programfiles\maven\Apache.maven.3.4
How to configure Maven?
- Add system variable C:\Maven. MVN_HOME
- Add path variable C:\Maven\bin
- create custom repository mvn_repo
- Update settings.xml in the conf folder with the above repository <localRepository>
- Run the mvn clean install command and check that dependencies are downloaded in the above repository
Why did we build the project after cloning it into our local machine?
- Generate source code
- Generating documentation from the source code
- Compiling the source code
- Packaging the compiled code into JAR files
- Installing the packaged code in the local repository, server or centralized location
What does it mean by mvn clean install?
- mvn: You are calling the maven executable, which means we need to install maven on the local computer
- clean: delete all previously compiled .java files and resources like properties. Your build starts from a clean state (delete target folder)
- install: Compile, test and package the java project and copy/install your built .jar/.war files into the local Maven repository
What happened when triggering the mvn test command?
- mvn: calling the maven executable
- test: compile the source code and execute test files
Difference between the mvn test and mvn verify?
mvn test
- This command is used to execute the tests in your project. It runs the tests in the
src/test
directory by default. - The
test
phase includes tasks such as compiling the test classes, executing the tests, and generating test reports. - This goal is typically used during the development phase to ensure that the unit tests pass.
mvn verify
- This command is used to run any checks on the results of integration tests to ensure quality criteria are met.
- The
verify
phase is typically executed after thetest
phase and includes additional checks or validations beyond unit testing, such as integration tests, code coverage checks, and other project-specific quality checks. - It is often used to ensure that the software is ready for release and meets certain quality standards
In summary:
- Use
mvn test
for executing unit tests during development. - Use
mvn verify
for additional checks and validations, especially those related to integration tests and overall project quality.
What is a pom.xml file?
- It has information regarding the project
- Configurations
- Versioning
- When we execute a task maven looking for the pom file
How to check the Maven version on a laptop?
mvn -version
11. Difference between mvn clean install and mvn test
mvn test
- Compiles the source code.
- Executes unit tests (if any) in the
src/test
directory. - Does not package or install artifacts.
- Suitable for running tests during development.
mvn clean install
- Cleans the project (deletes the
target
directory). - Compiles the source code.
- Executes unit tests.
- Packages the project’s artifacts (e.g., JAR) and installs them into the local Maven repository.
How does Maven help to build the project?
let’s say we are using a couple of frameworks in our code, for instance, selenium server, TestNG, JXL POI library etc. In order to use these frameworks within my application I need to include all the required jars in my application, I need to make them available. Let’s say we are developing scripts for a web application I need to make sure those jars are available during compile time, I need to bundle them in my distribution when am deploying it. I need to know what those jars are. That’s one of the common problems that we face sometimes. Sometimes we miss out on some jars, and sometimes we don’t know what jars are needed. So MAVEN helps us with this aspect
How does Maven help with dependencies and versioning?
Let’s say we have a particular jar and that jar has a dependency on other jars. Then I need to make sure that all my dependencies are closed, I need to make sure I have supplied all the required dependencies.
These are a few of the common problems that we face while architecting, developing, compiling and executing scripts on a web application. So MAVEN helps us by providing very elegant solutions to each of these problems