Skip to content

Latest commit

 

History

History
75 lines (49 loc) · 1.94 KB

cheat-sheet.md

File metadata and controls

75 lines (49 loc) · 1.94 KB

maven cheat sheet

Docker

Run maven container with docker using a different user than root:

  • First run the docker container:

    docker run -v $(pwd):/app -v ~/.m2:/var/maven/.m2 -ti --rm -u $(id -u):$(id -g) -e MAVEN_CONFIG=/var/maven/.m2 maven sh

  • Then when running any maven command specify the maven home with the following switch:

    -Duser.home=/var/maven

CLI

  • CLI Options
    • -am, --also-make: If project list is specified, also build projects required by the list
    • -amd, --also-make-dependents: If project list is specified, also build projects that depend on projects on the list
    • -e, --errors: Produce execution error messages
    • -N, --non-recursive: Do not recurse into sub-projects
    • -T,--threads: Thread count, for instance 2.0C where C is core multiplied
    • -X, --debug: Produce execution debug output

POM

Settings

# Specify settings.xml file from mvn cli
mvn -s <path/to/settings.xml> <goals or phases>
mvn -s ~/.m2/settings-custom.xml clean install

# Specify local repository path/location
mvn -Dmaven.repo.local=<pat/to/local/repo>

Useful Plugins

Help Plugin

# Check which profiles are actives
mvn help:active-profiles

# Get effective pom
mvn help:effective-pom -Doutput=effective-pom.xml

# To get value of maven property
mvn help:evaluate -Dexpression=project.version -q -DforceStdout -N

Dependency Plugin

# To view dependency tree
mvn dependency:tree

Exec Plugin

# Get maven project version
mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec

More Info