Sunday, February 12, 2023

Maven

Maven is a popular build automation tool used primarily for Java projects. It is an open-source tool developed by the Apache Software Foundation and is widely used for building, testing, and deploying software projects.

Maven provides a standard way to build and manage projects, making it easier for developers to collaborate on a project. It helps to manage the following aspects of a software project:

  1. Builds - Maven automates the build process and compiles, tests, and packages the code into a distributable format, such as a JAR or WAR file.

  2. Dependencies - Maven manages the dependencies of a project, automatically downloading and storing them in a local repository.

  3. Documentation - Maven can generate project documentation, such as reports and web sites, based on the project's metadata.

  4. Plugins - Maven provides a large number of plugins that can be used to extend its functionality, making it easier to integrate with other tools and technologies



Maven is a build automation tool that provides a standard way to build and manage projects in Java. In Maven, a build is divided into phases, and each phase represents a specific step in the build process. The default lifecycle in Maven is a pre-defined sequence of phases that builds, packages, and deploys a project.

The phases of the default Maven lifecycle are:

  1. validate - validate the project is correct and all necessary information is available
  2. compile - compile the source code of the project
  3. test - test the compiled source code using a suitable unit testing framework
  4. package - package the compiled code into a distributable format, such as a JAR or WAR file
  5. integration-test - process and deploy the package if necessary into an environment where integration tests can be run
  6. verify - run any checks to verify the package is valid and meets quality criteria
  7. install - install the package into the local repository, for use as a dependency in other projects locally
  8. deploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

Note that not all phases are executed every time a build is run. The specific phases that are executed depend on the goals that are specified in the command used to run the build.


A Project Object Model (POM) file is an XML file used by Maven to define a project's build and configuration details. The POM file contains information about the project, its dependencies, the build process, and the plugins used to build and manage the project.

Here are some of the key fields in a POM file:

  1. project: This section contains the general information about the project, such as its name, description, and the URL for the project's homepage.

  2. parent: If the project is a module of a larger project, the parent section is used to specify the parent project and its POM file.

  3. packaging: Specifies the type of artifact that will be generated by the build process, such as a JAR or WAR file.

  4. dependencies: Lists the external libraries that the project depends on, including the groupId, artifactId, and version of each library. Maven will automatically download and manage these dependencies.

  5. build: Defines the build process, including the plugins used, the output directory, and any additional configuration options.

  6. plugins: Lists the plugins used by Maven to perform various tasks, such as compiling the source code, testing the code, and generating reports.

  7. profiles: Specifies different configurations for the build process, allowing for different settings to be used for different environments, such as development and production.

  8. properties: Defines properties that can be used throughout the POM file, making it easier to manage common values such as versions and URLs.

These are some of the key fields in a POM file, but it can also contain other information such as distribution management, reporting, and more. The structure and content of a POM file can vary based on the needs of the project, and the flexibility of the POM file is one of the key strengths of Maven.


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>my-project</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>My Project</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>



Maven repositories are the locations where Maven stores the libraries and other dependencies that a project requires. There are three types of Maven repositories:

  1. Local Repository: A local repository is a repository that is stored on the developer's local machine. Maven automatically downloads and caches dependencies in the local repository, making it faster to build the project again in the future. The local repository is located in the .m2 directory in the user's home directory.

  2. Central Repository: The Central Repository is a publicly accessible repository that is maintained by the Apache Software Foundation. It contains a large number of popular libraries and is used by Maven as the default repository. When Maven cannot find a dependency in the local repository, it will look for it in the Central Repository.

  3. Remote Repository: A remote repository is a repository that is located on a remote server. Remote repositories are used to store internal or proprietary libraries that are not publicly accessible. Remote repositories can be hosted on a corporate network or in the cloud. Maven can be configured to use remote repositories by specifying their location in the settings.xml file.

Each repository has its own unique URL, and dependencies are retrieved from the repositories using their URL. When a project is built using Maven, it will first look for the required dependencies in the local repository. If the dependencies are not found, Maven will look for them in the Central Repository, and finally, in any specified remote repositories.


Maven Installation:

https://maven.apache.org/download.cgi






Maven Central Repository URL: https://repo.maven.apache.org/maven2/

Maven


No comments:

Post a Comment

Sample Game App Deployment on EKS cluster

 https://padmakshi.medium.com/setting-up-an-eks-cluster-and-deploying-a-game-application-a-step-by-step-guide-08790e0be117