Apache Maven - Overview

Last Updated: 2021-11-19

Add Log4j

Assume log4j properties are stored in src/main/resources/log4j.properties, add this to pom to enable log4j in unit test


Recursively add files


Set Dependency As Optional

Assume Project-A depends on slf4j, Project-B depends on Project-A, then slf4j will not be treated as dependency in Project-B; slf4j must be added to Project-B's pom in order to be used


Multi-module projects

You will be prompted for the version number for each module of the project. If you prefer that every module gets the same version as the parent POM, you can set the option autoVersionSubmodules to true. Now you will be asked only once for the release version and the next development version.


  • Parent-Child Approach: The one uses, a super pom define all the dependencies and version numbers via dependencyManagement, the child pom only need to define the dependency but not version number

    • Pro: a tree-structure hierarchy; child pom only define the dependencies that it needs
    • Con: a child can only have one parent
  • Group dependencies in one pom, and compile as "pom", then in each project, add that pom as a dependency, using the following code

  • Pro: do not need to explicitly list all the dependencies as parent-child approach; can add multiple pom as dependencies.
  • Con: it is a all-or-none approach, not sure if the extra loaded dependencies would affect the size or the efficiency of the final package.

Dependency Tree

$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Jetty HelloWorld
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] org.example:hello-world:jar:0.1-SNAPSHOT
[INFO] \- org.eclipse.jetty:jetty-server:jar:9.0.0:compile
[INFO]    +- org.eclipse.jetty:javax.servlet:jar:3.0.0.v201112011016:compile
[INFO]    +- org.eclipse.jetty:jetty-continuation:jar:9.0.0:compile
[INFO]    \- org.eclipse.jetty:jetty-http:jar:9.0.0:compile
[INFO]       \- org.eclipse.jetty:jetty-io:jar:9.0.0:compile
[INFO]          \- org.eclipse.jetty:jetty-util:jar:9.0.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Thu Jan 24 16:19:08 EST 2013
[INFO] Final Memory: 11M/68M
[INFO] ------------------------------------------------------------------------

Update Version

$ mvn versions:set -DnewVersion=``release version``

Set Main-Class

Set the main class in jar:



Copy Dependencies



In HDP 2.2, the jar of pig is published as pig-, however pom does not come with -h2: pig- can be found here

The right way to add it as dependency is put h2 as classifier:




It will update version to release version, tag code, commit and push. Meanwhile generate pom.xml.backup and release.properties files in the current dir.

$ mvn release:prepare


It will deploy package to nexus, checkout the tag code to local and update version to [new version]-SNAPSHOT, and cleanup the backup and properties files.

$ mvn release:perform