Maven

Resources for Apache Maven.

Common Commands

Generate a project from a template

mvn archetype:generate

Delete the target directory

mvn clean

List unused declared and used undeclared dependencies. For example, inspect the list and update the pom.xml file as needed to reduce the size of the build.

mvn dependency:analyze

Find goals for a plugin using help, e.g.,

mvn dependency:help

List project dependencies, e.g.,

mvn dependency:list

Display a tree of the dependencies

mvn dependency:tree

Deploy the artifact to remote repository

mvn deploy

Build and install to local repository

mvn install

Build and package. e.g., creates jar, war, etc.

mvn package

Checks the project

mvn validate

Configuring for Projects

For versions equal or greater than 3.3.1.

Suppose you want a project specfic Maven configuration for maven projects located in a folder named myproject.

Under myproject, create a directory named .mvn. e.g.,

cd myproject

mkdir .mvn

In the .mvn folder, create a valid Maven settings file named local-settings.xml. This can be done easily by copying the existing user Maven settings. e.g.,

cp ~/.m2/settings.xml .mvn/local-settings.xml

In the .mvn folder, create a maven.config file which contains the configuration options for the mvn command line. e.g.,

nano .mvn/maven.config

In the maven.config file, add / update this line to map --settings to the local-settings.xml. For project subdirectory mvn command context, the path to .mvn/local-settings.xml needs to be absolute. e.g.,

--settings /home/gilfoyle/myproject/.mvn/local-settings.xml

Here is our project file structure.

  • myproject
    • .mvn
      • local-settings.xml
      • maven.cofig
    • mysubmodule

For comparison with Adobe Experience Manager (AEM) Maven Project, the mysubmodule folder is named src.

For more information, refer to Configuring Apache Maven.

comments powered by Disqus