Maven Commands

With a simple command-line interface, Maven manages project dependencies, compiles source code, runs tests, and packages applications. Some basic Maven commands includes:

  • mvn clean: Cleans the project and removes all files generated by the previous build.
  • mvn compile: Compiles source code of the project.
  • mvn test-compile: Compiles the test source code.
  • mvn test: Runs tests for the project.
  • mvn package: Creates JAR or WAR file for the project to convert it into a distributable format.
  • mvn install: Deploys the packaged JAR/ WAR file to the local repository.
  • mvn site: generate the project documentation.
  • mvn validate: validate the project’s POM and configuration.
  • mvn idea:idea: generate project files for IntelliJ IDEA or Eclipse.
  • mvn release:perform: Performs a release build.
  • mvn deploy: Copies the packaged JAR/ WAR file to the remote repository after compiling, running tests and building the project.
  • mvn archetype:generate: This command is used to generate a new project from an archetype, which is a template for a project. This command is typically used to create new projects based on a specific pattern or structure.
  • mvn dependency:tree: This command is used to display the dependencies of the project in a tree format. This command is typically used to understand the dependencies of the project and troubleshoot any issues.

Generally when we run any of the above commands, we add the mvn clean step so that the target folder generated from the previous build is removed before running a newer build. This is how the command would look on integrating the clean step with install phase:

mvn clean install

Similarly, if we want to run the step in debug mode for more detailed build information and logs, we will add -X to the actual command. Hence, the install step with debug mode on will have the following command: 

mvn -X install

Consider a scenario where we do not want to run the tests while packaging or installing the Java project. In this case, we use -DskipTests along with the actual command. If we need to run the install step by skipping the tests associated with the project, the command would be:

mvn install -DskipTests

Maven Build Phases and Basic Maven Commands

Maven is a powerful project management tool that is based on POM (project object model) and used for project build, dependency, and documentation. It is a tool that can be used for building and managing any Java-based project. Maven makes the day-to-day work of Java developers easier and helps with the building and running of any Java-based project. In this article, we will discuss Maven build phases and basic Maven commands.

For more details on how Maven works, how to install Maven and its applications, please visit: Introduction to Apache Maven

Similar Reads

Maven Build Phases

Maven build phases are a sequence of steps or stages that Maven follows when executing a build lifecycle. These build phases are standardized and define the order in which Maven executes various goals. Each build phase represents a different stage in the lifecycle of a project....

Maven Commands

With a simple command-line interface, Maven manages project dependencies, compiles source code, runs tests, and packages applications. Some basic Maven commands includes:...