Maven Cheat Sheet

Here's a cheat sheet for Maven with commonly used commands and their descriptions.

1. Project Creation 

mvn archetype:generate: Create a new Maven project from an archetype (template). 

2. Build Lifecycle 

mvn clean: Cleans the build by deleting the target directory. 

mvn compile: Compiles the source code of the project. 

mvn test: Runs the tests for the project. 

mvn package: Packages the compiled code into a distributable format, such as a JAR or WAR file. 

mvn install: Installs the packaged artifact into the local repository for use by other projects. 

mvn deploy: Deploys the artifact to a remote repository for sharing with other developers or projects. 

3. Dependency Management 

mvn dependency:tree: Displays the dependency tree of the project. 

mvn dependency:resolve: Resolves and downloads dependencies required by the project. 

mvn dependency:purge-local-repository: Clears the local repository of all dependencies. 

4. Plugin Management 

mvn plugin:help: Displays help information about Maven plugins. 

mvn plugin:search: Searches for Maven plugins in the remote repository. 

mvn plugin:report: Generates various reports for the project. 

mvn plugin:clean: Cleans up plugin artifacts and metadata. 

5. Project Information 

mvn help:describe: Provides detailed information about a specific Maven goal. 

mvn help:effective-pom: Displays the effective POM (Project Object Model) of the project. 

mvn help:system: Displays information about the system Maven is running on. 

6. Maven Profiles 

mvn help:active-profiles: Displays the active profiles for the current project. 

mvn help:all-profiles: Displays all available profiles for the current project. 

mvn <command> -P <profile>: Executes a Maven command using a specific profile. 

7. Maven Wrapper 

./mvnw <command>: Executes a Maven command using the Maven Wrapper (useful for projects without a local Maven installation). 

./mvnw.cmd <command>: Executes a Maven command using the Maven Wrapper on Windows. 

This cheat sheet covers some of the most commonly used Maven commands and their descriptions. Maven provides many more features and options for project management and building automation, so be sure to consult the official Maven documentation for more detailed information on specific commands and configurations.

Check out Maven commands: Apache Maven Commands

Comments