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), |
| 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>, |
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 |
| 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 |
| artifact ID | ## This element indicates the unique base name of the primary artifact being generated by this project. The primary artifact |
| version | ## This element indicates the version of the artifact generated by the project. Maven goes a long way to help you with version |
| properties | ## Maven properties are value placeholder, their values are accessible anywhere within a POM by using the notation ${X}, |
| 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> |