Maven

 



Maven:
    Maven is a software management and comprehension tool based on the concept of the Project Object Model (POM) which can manage project build, reporting, and documentation from a central piece of information.

Maven is a popular open-source build tool developed by the Apache group. It's chiefly used for Java-based projects.

To download dependencies we can download from "https://mvnrepository.com/", instead of visiting the official website of each software.

All build systems are essentially the same:
    > Compile Source code.
    > Copy Resource
    > Compile and Run Tests
    > Package Project
    > Deploy Project
    > Cleanup

To install maven run the below command:

$ sudo yum update && sudo yum install maven -y

Maven requires JDK (Java Development Kit) to be installed.

$ sudo yum install java-1.8.0-openjdk -y

To verify maven version run the below command:

$ mvn -v

Maven projects will have a "pom.xml" config file.
> It has all the information regarding project and configuration details.
> It has the description of the project, details regarding the versioning and configuration management of the project.
> The XML file is in the project home directory. Maven searches for the POM in the current directory when any task is to be executed.
> Dependencies refer to the java libraries that are needed for the project. Repositories refer to the directories of the package JAR file.
> If the dependencies are not present in your local repository, then maven downloads them from a central repository and stores them in the local repository.
> "Build Profiles" refer to the set of configuration values, that are required to build a project using differnt configurations.
> Different build profiles are added to the POM files when enabling different builds.
> A "Build Profile" helps in customizing build for different environments.
> The plugins are used to perform specific goal.

Maven Architecture:

Maven Build Lifecycle:

Default Lifecycle:

1. Generate-sources/generate-resources

2. Compile                # It will covert all the java files to the object/class file.

3. Test                       # Maven will do a "Unit Test", Developer will write this test code to test his code.
4. Package                # Jar (Java Archive) | war (Web Archive) | ear (Enterprise based Archive)                                                  It will create the package of all the class/object files.

5. Install                   # copy the deliverable package in the local repository (.M  folder).

6. Deploy                 # deploying the application at any server in any env.

There is also a "Clean, Site" lifecycle.

1. Clean                    # Will delete all the "run-time" files.

2. Site                       # Will take the complete details of a project and what all dependencies are there for the project.



Maven Project directory structure will be the same for all the projects as shown in the below image.




Maven uniquely identifies a project using an arbitrary project group identifier, arbitrary name of project, and version of the project.

GAV syntax: goupID:artifactID:version

version formate: {Major}.{Minor}.{Maintenance}
Add "-SNAPSHOT" to identify in development

Maven Goals:

$ mvn archetype:generate  # This will generate the required directory structure for a new project.
$ mvn install          # Invokes generate* and compile, test, pakcage, integration-test, install.
$ mvn clean  # Invokes just clean.
$ mvn clean compile  # Clean old builds and execute generate*, compile.
$ mvn compile install         # Invokes generate*, compile, test, integration-test, package, install.
$ mvn test clean         # Invokes generate*, compile, test then cleans

Comments