DEV Community

Aditya Pratap Bhuyan
Aditya Pratap Bhuyan

Posted on

Maven Commands Cheat Sheet

Image description

Basic Commands

1. mvn clean

Remove all files generated by the previous build.

mvn clean

2. mvn compile

Compile the source code of the project.

mvn compile

3. mvn test

Run the tests for the project.

mvn test

4. mvn package

Compile, test, and package the code into a JAR/WAR file.

mvn package

5. mvn install

Install the package into the local repository.

mvn install

6. mvn deploy

Deploy the package to a remote repository.

mvn deploy

7. mvn validate

Validate the project is correct and all necessary information is available.

mvn validate

8. mvn site

Generate a site for the project.

mvn site

9. mvn clean install

Clean the project and install it.

mvn clean install

10. mvn clean package

Clean the project and package it.

mvn clean package

Running Specific Goals

11. mvn test-compile

Compile the test source code.

mvn test-compile

12. mvn exec:java

Execute a Java program.

mvn exec:java -Dexec.mainClass="com.example.Main"

13. mvn clean validate

Clean the project and validate it.

mvn clean validate

14. mvn clean site

Clean the project and generate a site.

mvn clean site

15. mvn install:install-file

Manually install a JAR file into the local repository.

mvn install:install-file -Dfile=path/to/your.jar -DgroupId=com.example -DartifactId=your-artifact -Dversion=1.0 -Dpackaging=jar

16. mvn dependency:tree

Display the dependency tree.

mvn dependency:tree

17. mvn dependency:resolve

Resolve project dependencies.

mvn dependency:resolve

18. mvn help:effective-pom

Display the effective POM for the project.

mvn help:effective-pom

19. mvn versions:display-dependency-updates

Display available updates for dependencies.

mvn versions:display-dependency-updates

20. mvn checkstyle:checkstyle

Run the Checkstyle plugin to check code style.

mvn checkstyle:checkstyle

Configuration and Debugging

21. mvn -X

Run Maven in debug mode.

mvn -X

22. mvn -e

Show the full stack trace for errors.

mvn -e

23. mvn -DskipTests

Skip running tests.

mvn package -DskipTests

24. mvn -DskipITs

Skip running integration tests.

mvn verify -DskipITs

25. mvn -Dtest=TestClass#testMethod

Run a specific test method.

mvn test -Dtest=TestClass#testMethod

26. mvn -P profile

Activate a specific Maven profile.

mvn package -Pproduction

27. mvn help:effective-settings

Display the effective settings.xml file.

mvn help:effective-settings

28. mvn help:effective-pom -Ddebug

Display the effective POM with debug information.

mvn help:effective-pom -Ddebug

29. mvn -DskipTests=true

Skip tests during the build.

mvn package -DskipTests=true

30. mvn -DskipTests=false

Run tests during the build.

mvn package -DskipTests=false

Advanced Commands

31. mvn deploy:deploy-file

Deploy a file to a remote repository.

mvn deploy:deploy-file -Durl=http://your-repo-url -Dfile=path/to/your.jar -DgroupId=com.example -DartifactId=your-artifact -Dversion=1.0 -Dpackaging=jar

32. mvn clean verify

Clean the project and run verification tasks.

mvn clean verify

33. mvn dependency:build-classpath

Build the classpath for the project.

mvn dependency:build-classpath

34. mvn dependency:copy-dependencies

Copy project dependencies to a specified location.

mvn dependency:copy-dependencies -DoutputDirectory=lib

35. mvn resources:resources

Process the resources of the project.

mvn resources:resources

36. mvn release:prepare

Prepare for a release.

mvn release:prepare

37. mvn release:perform

Perform a release.

mvn release:perform

38. mvn sonar:sonar

Run SonarQube analysis.

mvn sonar:sonar

39. mvn clean install -Pproduction

Clean and install the project with the production profile.

mvn clean install -Pproduction

40. mvn site:deploy

Deploy the generated site.

mvn site:deploy

Lifecycle Phases

41. mvn validate

Validate the project structure.

mvn validate

42. mvn compile

Compile the project source code.

mvn compile

43. mvn test

Run tests.

mvn test

44. mvn package

Package the compiled code into a JAR or WAR.

mvn package

45. mvn install

Install the package into the local repository.

mvn install

46. mvn deploy

Deploy the package to a remote repository.

mvn deploy

47. mvn verify

Run any checks on the results of integration tests to ensure quality criteria are met.

mvn verify

48. mvn clean

Remove all files generated by the previous build.

mvn clean

49. mvn site

Generate a site for the project.

mvn site

50. mvn deploy-site

Deploy the generated site.

mvn deploy-site

Running with Profiles

51. mvn clean install -Pprofile

Clean and install the project using a specific profile.

mvn clean install -Pprofile

52. mvn test -Ptest

Run tests with a specific profile.

mvn test -Ptest

53. mvn package -Pproduction

Package the project with the production profile.

mvn package -Pproduction

54. mvn verify -Pdev

Verify the project with the development profile.

mvn verify -Pdev

55. mvn clean -Ptest

Clean the project using a test profile.

mvn clean -Ptest

Custom Goals and Plugins

56. mvn exec:java

Run a Java program.

mvn exec:java -Dexec.mainClass="com.example.Main"

57. mvn scala:compile

Compile Scala sources.

mvn scala:compile

58. mvn javadoc:javadoc

Generate Javadoc.

mvn javadoc:javadoc

59. mvn checkstyle:check

Run Checkstyle to check code style.

mvn checkstyle:check

60. mvn pmd:pmd

Run PMD to check for coding issues.

mvn pmd:pmd

61. mvn license:format

Format the license headers in the code.

mvn license:format

62. mvn dependency:analyze

Analyze the dependencies.

mvn dependency:analyze

63. mvn site:deploy

Deploy the generated site.

mvn site:deploy

64. mvn clean site -Pproduction

Clean the project and generate the site with the production profile.

mvn clean site -Pproduction

65. mvn exec:java -Dexec.mainClass="com.example.Main" -Dexec.args="arg1 arg2"

Run a Java program with arguments.

mvn exec:java -Dexec.mainClass="com.example.Main" -Dexec.args="arg1 arg2"

66. mvn resources:copy-resources

Copy resources to the output directory.

mvn resources:copy-resources

67. `mvn resources:resources -Dinclude="/.xml"`*

Process only XML resources.

mvn resources:resources -Dinclude="**/*.xml"

68. mvn release:prepare

Prepare a release.

mvn release:prepare

69. mvn release:perform

Perform a release.

mvn release:perform

70. mvn clean validate package

Clean, validate, and package the project.

mvn clean validate package

Debugging and Troubleshooting

71. mvn -X

Run Maven in debug mode.

mvn -X

72. mvn -e

Show full stack trace for errors.

mvn -e

73. mvn -DskipTests

Skip running tests.

mvn package -DskipTests

74. mvn -DskipITs

Skip running integration tests.

mvn verify -DskipITs

75. mvn -Dtest=TestClass#testMethod

Run a specific test method.

mvn test -Dtest=TestClass#testMethod

76. mvn -P profile

Activate a specific Maven profile.

mvn package -Pproduction

Useful Maven Commands

77. mvn dependency:tree

Display the dependency tree.

mvn dependency:tree

78. mvn help:effective-pom

Display the effective POM.

mvn help:effective-pom

79. mvn help:effective-settings

Display the effective settings.xml.

mvn help:effective-settings

80. mvn help:active-profiles

Display the active profiles.

mvn help:active-profiles

81. mvn help:all-profiles

Display all profiles.

mvn help:all-profiles

82. mvn help:system

Display system properties.

mvn help:system

83. mvn help:effective-settings

Display the effective settings.

mvn help:effective-settings

84. mvn help:effective-pom

Display the effective POM.

mvn help:effective-pom

85. mvn help:active-profiles

Display the active profiles.

mvn help:active-profiles

86. mvn help:all-profiles

Display all profiles.

mvn help:all-profiles

87. mvn help:system

Display system properties.

mvn help:system

88. mvn help:effective-settings

Display the effective settings.

mvn help:effective-settings

Conclusion

This cheat sheet provides a comprehensive list of common Maven commands. Use these commands to streamline your build and project management processes.

Top comments (0)