MAVEN basics

·

3 min read

Maven is a project management tool

Is primarily used for projects developed in Java. Maven is driven by a project object model commonly known as POM. This is the central repository for all dependencies.

Easily integrate them with continuous integration tools such as Jenkins. It is also responsible for project reporting

POM.xml in maven is a collection of Java project dependencies .

Maven then downloads everything from the internet and stores it in one repository: local repository, central repository, remote repository.

The three build lifecycles are −

  • Clean: Cleans up artifacts created in previous builds.

  • Default: Used to create the application.

  • Site: Create a site document for your project.

Default lifecycle in maven

  • validate.

  • compile.

  • test.

  • package.

  • verify.

  • install.

The Maven settings.xml file contains elements to define the values ​​needed for various configurations of Maven execution.

Contains the following configurations:

  • Proxy configuration

  • Local repository configuration

  • Remote repository configuration

  • Central repository configuration

  1. POM refers to the XML files that have all the information regarding project and configuration details.

  2. The main configuration file is pom.xml.

  3. It has a description of the project, and details regarding the versioning and configuration management of the project. The XML file is in the Project home directory.

  4. POM XML contains metadata, dependencies, kind of projects, kind of output, and descriptions.

A SNAPSHOT repository is used to store artifacts that are under active development and are subject to frequent changes. These artifacts are typically denoted by a version number ending in -SNAPSHOT

A RELEASE repository is used to store artifacts that have been finalized and are ready for production use. These artifacts are typically denoted by a version number without the -SNAPSHOT suffix. For example, if the current version of an artifact is 1.0-SNAPSHOT, the RELEASE version would be 1.0.

There are three types of Maven repositories:

  • Local repository: Local repository is the developer's repository where all project materials are stored. The local repository contains all the dependency jars.

  • Remote repository: A remote repository is a repository that resides on a server and is used when Maven needs to download dependencies. When something is required from a remote repository, it is first downloaded to the local repository and then used.

  • Central Repository: A central repository is a Maven repository that needs dependencies and takes action if those dependencies are not found in the local repository.

Common issues you face with Maven

Dependency Conflicts:

Maven manages dependencies for your project, and it can sometimes encounter conflicts between different versions of the same library or incompatible dependencies. This can lead to compilation errors or runtime issues. To resolve this, you can use Maven's dependency management features, such as excluding specific dependencies or explicitly specifying versions

Proxy and network issues:

If your organization uses a proxy server or has network restrictions, Maven may face difficulties in connecting to remote repositories to download dependencies. You may need to configure Maven to work with your proxy settings or set up a local repository mirror.

The minimum required elements for a POM are the project root, model version, group ID, artifact ID, and version.

Maven's main objective is to make the process of creating and maintaining Java projects easier by standardizing project structure, dependency management, and build lifecycle.