mvn [life cycle commands] [plugin:target] [-Doption=value] [dots]
mvn -X- Will print more logs
mvn -T 1C- Create threads as much as the number of coresmvn -T 2C- Create threads double the number of cores
mvn archetype:generate
mvn archetype:generate -DgroudId=<Artifact Group | Package name> -DartifactId=<Artifact ID | Project name> -DinteractiveMode=false
mvn archetype:generate -DgroudId=<Artifact Group | Package name> -DartifactId=<Artifact ID | Project name> -DarchetypeArtifactId=<Archetype Artifact ID | Existing maven template project ID> -DinteractiveMode=false
Run the following commands inside the folder containing pom.xml files
mvn cleanmvn testmvn compilemvn packagemvn install- Install Artifact locally-o- Run in offline mode
mvn install -Dmaven.test.skip=true- Execute 'install' life cycle without running tests
- Doesn't compile test files at all
mvn install -DskipTests- Short alternative to skip tests
- Here test files are compiled, but it is not run
mvn -Dtest=TestClass#testMethod test
- Run with particular profile -
mvn -Pprod - Ref: http://maven.apache.org/guides/introduction/introduction-to-profiles.html
-B- Runs Maven in batch mode. It avoids Maven's reporting of downloading progress.-e- Configures Maven to report detailed information about errors-pl- Run a module alone in multi-module project setup-am- Additional parameter to resolve local dependency in multi-module project setup. E.g.mvn -pl clean install -am module-b
mvn dependency:analyze- Helps to get information on "Used undeclared dependencies", "Unused declared dependencies" etc.mvn -Dverbose dependency:tree- To see dependency tree-Dverbose- This will show options not displayed because of duplication-Dincludes=[group]:[artifact_name]:[type]:[version]- E.g.,mvn -Dverbose dependency:tree -Dincludes=:hibernate*. Use wild card*to cover different possibilities- Ref: filtering-the-dependency-tree
- Ref: resolving-conflicts-using-the-dependency-tree
mvn versions:display-dependency-updates
- Run
mvn compile dependency:tree >> temp_v01.txtto store dependency tree to the file - Then make the necessary changes
- And, run
mvn compile dependency:tree >> temp_v02.txtto store new dependency tree to the file - Compare 2 files to see the difference
mvn -U- Check for updated snapshots on remote repositories
mvn install:install-file -Dfile=my-jar.jar -DgroupId=com.shaunthomas999 -DartifactId=my-jar -Dversion=LOCAL -Dpackaging=jar
mvn dependency:copy -Dartifact="com.shaunthomas999.project:my-sample-project:RELEASE:jar" -DoutputDirectory=.
<scope> values
-
compile - default - transitive
-
provided - provided at runtime by JDK or container - not transitive (available in compile and test only). E.g. servlet API
-
system - like provided but dependency path should be explicitly specified by
<systemPath>property<dependency> <groupId>com.baeldung</groupId> <artifactId>custom-dependency</artifactId> <version>1.3.2</version> <scope>system</scope> <systemPath>${project.basedir}/libs/custom-dependency-1.3.2.jar</systemPath> </dependency>
-
runtime - required at runtime - not in compile time but in test and runtime. E.g. JDBC driver
-
test - required for testing - not transitive. E.g., JUnit
-
import - only available for dependency type
<type>pom</type>. Replace declaration with effective pom that is imported.
provided and test scope will never end-up in main project
- https://www.baeldung.com/maven-dependency-scopes
- https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
mvn versions:set -DgenerateBackupPoms=false -DnewVersion=<Put_New_Version_Here>
mvn deploy