Skip to main content

Maven in Brief

What is Maven

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.

Below are features provided by maven:

  • Build Automation Tool
  • Dependency Management Tool
  • Project Management Tool
  • Standard approach to building software
  • Command line tool
  • IDE Integration
  • Managed by Apache Software Foundation

Terminologies

  • POM(Project Object Model)
    • POM is an XML file, and this file really describes the configuration and the customization for our project. So it's going to spell out the different plugins, different dependencies and different profiles that we use to construct our project.
    • Within this POM, minimal requirement is to have GAV parameters. Maven uses a coordinate system, where you specify GAV - group ID, artifact ID and version number.
  • Repositories
    • where all the built artifacts and dependencies stored.
    • There are 2 types of repo. - local(cache) and remote.
      • Local repository take precedence for dependencies to download.
      • Local repo created as hidden .m2 directory in home dir. of userid
  • Lifecycle and Phase
    • When maven runs the build process it goes through it build lifecyle. There is clearly defined process of building and distributing the artifact.
    • There are 3 build lifecycles: default, clean and site
      • default - Handles project management. This is majorly used lifecycle.
      • clean - Handles project cleaning.
      • site - Create project site documentation.
    • Lifecycle consists of Phases. Phase is a stage in the lifecycle through which build go through.
    • Phases of default lifecycle For the complete list of default lifecycle phases please refer this link
      • validate - Validates the project if contains all necessary information
      • compile - Compile the source code
      • test - Test the source code using unit test cases written under src/test/ directory
      • package - Create package containing with all compiled code ex. jar, war which contains classes of java
      • verify - Runs integration checks ex. source code is written according to predefined checkstyle
      • install - Install the package to local repository, means copy the package from target directory to ~/.m2/repository/groupID/artifactID/versionNumber/directory
      • deploy - Upload the artifact to remote repository
    • When any phase is getting executed in lifecycle, maven execute all precedence phases.
      • Ex. when we run mvn package maven will run all phases validate, compile, testbefore "package" in order
  • Plugins and Goals
    • Individual build phase is made up of Plugin
    • Plugin is a collection of goals with default goal attached to it.
    • Ex. when we run mvn package maven default run plugin jar which has default goal jar
    • Plugin and Goal are described as plugin:goal ex. jar:jar
    • Goal performs the actual action in build process.
    • Few example of default lifecycle phase and their default plugin and goal
    • Default Lifecycle Phase Default Plugin:Goal
      compile compiler:compile
      test surefire:test
      package jar:jar
      install install:install
      deploy deploy:deploy
  • How to configure Plugins and Goals
    • A Plugin contains default and other goals. Ex. compiler plugin contains 2 goals: compile and testCompile
    • Plugin and Goal can be configured within POM.xml and command line.
    • Using POM.xml
    •                     
      <plugin>
         <groupId>com.mycompany.example</groupId>
         <artifactId>display-maven-plugin</artifactId>
         <version>1.0</version>
         <executions>
           <execution>
             <phase>process-test-resources</phase>
             <goals>
               <goal>time</goal>
             </goals>
           </execution>
         </executions>
       </plugin>
                          
                      
    • Using Command line
      • mvn help:effective-pom Here help is plugin and effective-pom is goal.
      • This command would return super pom.xml file details.

Comments

Popular posts from this blog

How to skip resources, compiler, surfire, install plugin in maven's default build process

When we want to use maven command line to upload zip type artifact to artifact repository then we don't want resources, compiler, surefire, install phases in maven process, only assembly would be enough. To skip particular phases go to each plugin's original website phase according to latest running plugin version download the same to our own project refer the skip phase configuration of particular phase, either it can be done command line or as part of the build-plugin-configuration. Example using POM.xml file <project> [...] <build> <plugins> <plugin> <groupId...

How to clone Github repository using SSH

Run ssh-keygen Upload ssh public key to github account curl -u "gitUsername:password" --data '{"title":"keyName","key":"'"$(cat ~/.ssh/id_rsa.pub)"'"}' https://api.github.com/user/keys Sample output of ssh public key upload command { "id": 1234567890, "key": "ssh-rsa aaaaaaaaaaaaaaaaaaaa/dddd/+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "url": "https://api.github.com/user/keys/123456...

Install AWS CLI on Ubuntu localhost using Ansible Playbook

Install AWS CLI on Ubuntu localhost using Ansible Playbook --- - hosts: localhost tasks: - name: Installing Unzip package package: name: unzip state: present when: ansible_facts['os_family'] == "Debian" become: true - name: Create awscli directory in home directory file: path: ~/awscli state: directory mode: '0755' - name: Download bundled installer zip file get_url: url: https://s3.amazonaws.com/aws-cli/awscli-bundle.zip dest: ~/awscli/awscli-bundle.zip - name: Extract zip file unarchive: src: ~/awscli/awscli-bundle.zip dest: ~/awscli - name: Run install command shell: /home/ubuntu/awscli/awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws become: true Same script is also avail...