Maven Cheatsheet

Some commands need a dash and some don't make sure you run the right command, also you can un multiple commands via a single mvn command.

Maven Commandline
version
mvn -version
help
mvn -help
clean
mvn clean
package
mvn package
Effective POM (shows all inheritance)
mvn help:effective-pom
dependency - tree
mvn dependency:tree
dependency - resolve all
mvn dependency:go-offline
dependency - clear artifacts from local repo
mvn dependency:purge-local-repository
dependency - get sources
mvn dependency:sources
Display phases of a lifecycle
mvn help:describe -Dcmd=clean
Maven Tests
mvn test                 # run all tests
mvn -Dtest=ServiceImplTest test                     # run all tests in a class
mvn -Dtest=ServiceImplTest#specificTest test        # run a specific test in a class
mvn -Dtest=ServiceImplTest#specificTest* test       # run a specific tests in a class using pattern

mvn package -Dmaven.test.skip=true                  # skip running all tests
mvn package -DskipTests                             # skip running surefire tests
mvn package -DskipITs                               # skip running failsafe integration tests
Proiles Activing or Deactiving
mvn package -P <profile-1>,<profile-2>              # activing profiles
mvn package -P !<profile-1>,<profile-2>             # use the ! to deactive a profile 
Profiles view active
mvn help:active-profiles
Release prepare
mvn clean release:prepare

Note: Maven will ask you for the release (select default) and the snapshot (select default), 
two files will be created a backup of the POM and a release.properties file.
Release prepare (dryrun)
mvn release:prepare -DdryRun=true

Note: dryRun will will put not change anything but ive us the output, good for checking before you run for real.
Release perform
mvn release:perform

Note: This will also deploy (Packagecloud or Nexus for example)
Release rollback
mvn release:rollback

Note: this will remove the backup POM, remove the release.properties file and rollback the <version>, 
however it won't update github this has to be done manually.

Below are the properties of a POM file

POM Breakdown
xml
## This defines the XML version and any encoding, the XML declaration describes some of the most general properties of 
## the document, telling the XML processor that it needs an XML parser to interpret this document <?xml version="1.0" encoding="UTF-8"?>
project, schema and namespacing
## This is the top level element and defines the schema used and any namespaces, also defines all the rules and elements that can be used

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
model version
## This element indicates what version of the object model this POM is using.

<modelVersion>4.0.0</modelVersion>
group ID
## indicates the unique identifier of the organization or group that created the project. The groupId is one of the key 
## identifiers of a project and is typically based on the fully qualified domain name of your organization <groupId>uk.co.datadisk</groupId>
artifact ID
## This element indicates the unique base name of the primary artifact being generated by this project. The primary artifact 
## for a project is typically a JAR file. Secondary artifacts like source bundles also use the artifactId as part of their
## final name <artifactId>hello-world</artifactId>
version
## This element indicates the version of the artifact generated by the project. Maven goes a long way to help you with version 
## management and you will often see the SNAPSHOT designator in a version, which indicates that a project is in a state
## of development <version>0.0.1-SNAPSHOT</version>
properties
## Maven properties are value placeholder, their values are accessible anywhere within a POM by using the notation ${X}, 
## where X is the property, or they can be used by plugins as default values <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>11</java.version> <maven.compiler.source>${java.version}</maven.compiler.source> <maven.compiler.target>${java.version}</maven.compiler.target> </properties>
dependencies
## Any dependencies required will be automatically downloaded from the Maven Repository

<dependencies>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.8.1</version>
    <dependency>
</dependencies>