Top 20 Maven Commands

In this article we will look into some of the most commonly used Maven commands.

Maven Commands

Maven Life Cycle

Before we jump to the Maven commands, let us briefly discuss the maven life cycle.

Maven Commands
  1. Validate: Validates if the project structure is correct.
  2. Compile: It compiles the source code and stores the . class files in target/classes folder.
  3. Test: It runs unit tests for the project.
  4. Package:  builds the maven project and packages them into a JAR, WAR etc
  5. Integration Test: It runs the integration tests for the project.
  6. Verify: It runs any checks on results of integration tests to ensure quality criteria are met
  7. Install: Installs the packaged code to the local Maven repository.
  8. Deploy: It copies the packaged code to the remote repository.

Maven follows the sequential order of commands.  For example if I do, mvn install -> It will perform all the previous steps also.

So, mvn install will perform -> verify->compile->test->package->integration test->verify->then finally install

Maven Commands

mvn –version

This command is used to check the version of maven installed in the System. It also specifies the java version which is used by maven to compile the Java source code.

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 1.8.0_275, vendor: AdoptOpenJDK, runtime: /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"


mvn validate

The mvn validate command is one of the core Maven commands that is used to validate the project configuration and check if all the necessary information is available for the build process.

$ mvn validate
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.177 s
[INFO] Finished at: 2023-07-04T10:34:33+05:30
[INFO] ------------------------------------------------------------------------

mvn compile

This command compiles the source code and keeps the compiled resources in the target folder.
Please note that it recompiles only if  it detects any change in source code.

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building YourProject 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ your-project ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ your-project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to /path/to/your/project/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.827 s
[INFO] Finished at: 2023-07-04T10:30:00+00:00
[INFO] ------------------------------------------------------------------------

mvn clean

IDeletes the target directory: Maven deletes the target directory, which contains all the output files generated during the build process, including compiled classes, test reports, generated artifacts, and other temporary files.

mvn clean command is often used as a preliminary step before executing other Maven commands, such as mvn compile, mvn test, or mvn package. It helps in avoiding any potential issues caused by leftover files from previous builds and provides a clean slate for the subsequent build process.

[INFO] Scanning for projects...
[INFO] -----------------------< com.example:my-project >------------------------
[INFO] Building my-project 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ my-project ---
[INFO] Deleting directory /path/to/project/target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.823 s
[INFO] Finished at: 2023-07-03T09:25:00+00:00
[INFO] ------------------------------------------------------------------------

mvn clean compile

First it deletes the target folder , then it compiles the source code and puts the compiled resources in the target folder.

[INFO] Scanning for projects...
[INFO] ---------------------< com.example:my-project >----------------------
[INFO] Building my-project 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ my-project ---
[INFO] Deleting <project_directory>/target
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ my-project ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling X source files to <project_directory>/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.345 s
[INFO] Finished at: 2023-07-03T12:34:59Z
[INFO] ------------------------------------------------------------------------

mvn test-compile

This command compiles the test source code without executing the tests. It ensures that the test classes are compiled and the necessary dependencies are resolved, but it doesn’t run the actual tests.

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to <project_directory>/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory <project_directory>/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to <project_directory>/target/test-classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.690 s
[INFO] Finished at: 2023-07-03T23:50:09+05:30
[INFO] ------------------------------------------------------------------------

mvn clean test-compile

It first deletes the target folder by executing the clean operation and then invokes the test-compile command.

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo ---
[INFO] Deleting <project_directory>/target
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to <project_directory>/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory <project_directory>/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to <project_directory>/target/test-classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.749 s
[INFO] Finished at: 2023-07-03T23:51:45+05:30
[INFO] ------------------------------------------------------------------------

mvn test

This command executes the tests in your project. It compiles the test source code, resolves dependencies, and runs the test classes. It generates a test report that provides information about the test results, such as the number of tests executed, passed, failed, and skipped.

$ mvn test
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory <project_directory>/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.demo.DemoApplicationTests
-----------
-----------
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.611 s - in com.example.demo.DemoApplicationTests
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.400 s
[INFO] Finished at: 2023-07-04T10:30:09+05:30
[INFO] ------------------------------------------------------------------------

Important Note: mvn test-compile is used for compiling the test code, while mvn test is used for executing the tests.

mvn package

As discussed earlier, Maven will execute all the steps till package as depicted in the life cycle.

This compiles the source code, runs the tests and finally bundles the compiled resources to a jar or war.

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory <project_directory>/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.demo.DemoApplicationTests
------------------------
------------------------
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.986 s - in com.example.demo.DemoApplicationTests
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-jar-plugin:3.2.2:jar (default-jar) @ demo ---
[INFO] Building jar: <project_directory>/target/demo-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.6.4:repackage (repackage) @ demo ---
Downloading from central: 
----------------
---------------
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.339 s
[INFO] Finished at: 2023-07-03T23:52:59+05:30
[INFO] ------------------------------------------------------------------------

mvn clean package

It first performs the clean operation by deleting the target folder and then invokes the package command.

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo ---
[INFO] Deleting <project_directory>/target
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to <project_directory>/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory <project_directory>/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to <project_directory>/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.demo.DemoApplicationTests
------------------------
------------------------
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.938 s - in com.example.demo.DemoApplicationTests
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-jar-plugin:3.2.2:jar (default-jar) @ demo ---
[INFO] Building jar: <project_directory>/target/demo-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.6.4:repackage (repackage) @ demo ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.558 s
[INFO] Finished at: 2023-07-03T23:55:48+05:30
[INFO] ------------------------------------------------------------------------


mvn verify

The mvn verify command is typically used as part of the continuous integration (CI) process or before deploying the project to a production environment. It provides a comprehensive verification of the project’s build, tests, and additional checks, ensuring that everything is in a valid and reliable state.

$ mvn verify
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory <project_directory>/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
----------------
----------------
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.587 s - in com.example.demo.DemoApplicationTests
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-jar-plugin:3.2.2:jar (default-jar) @ demo ---
[INFO] Building jar: <project_directory>/target/demo-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.6.5:repackage (repackage) @ demo ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.138 s
[INFO] Finished at: 2023-07-04T10:37:04+05:30
[INFO] ------------------------------------------------------------------------

mvn install

It does the following:

  • compiles the source code and stores in the target/classes folder
  • compiles the test source code and stores in the taget/test-classes folder
  • runs the test
  • builds the jar or war in the target folder
  • Copies the pom to the local Maven respository
  • Copies the jar or war from the target folder to the local Maven respository
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory <project_directory>/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.demo.DemoApplicationTests
------------
-----------
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.667 s - in com.example.demo.DemoApplicationTests
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-jar-plugin:3.2.2:jar (default-jar) @ demo ---
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.6.4:repackage (repackage) @ demo ---
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ demo ---
[INFO] Installing <project_directory>/target/demo-0.0.1-SNAPSHOT.jar to <m2_directory>/.m2/repository/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-SNAPSHOT.jar
[INFO] Installing <project_directory>/pom.xml to <m2_directory>/.m2/repository/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.182 s
[INFO] Finished at: 2023-07-03T23:58:22+05:30
[INFO] ------------------------------------------------------------------------

mvn clean install

It first performs the clean operation by deleting the target folder and then invokes the install command.

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo ---
[INFO] Deleting <project_directory>/target
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to <project_directory>/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory <project_directory>/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to <project_directory>/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.demo.DemoApplicationTests
------------
-----------
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.667 s - in com.example.demo.DemoApplicationTests
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-jar-plugin:3.2.2:jar (default-jar) @ demo ---
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.6.4:repackage (repackage) @ demo ---
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ demo ---
[INFO] Installing <project_directory>/target/demo-0.0.1-SNAPSHOT.jar to <m2_directory>/.m2/repository/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-SNAPSHOT.jar
[INFO] Installing <project_directory>/pom.xml to <m2_directory>/.m2/repository/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.182 s
[INFO] Finished at: 2023-07-03T23:58:22+05:30
[INFO] ------------------------------------------------------------------------

mvn deploy

The mvn deploy command, along with the distributionManagement configuration in your Maven project, is used to upload your project artifacts to a remote repository. It builds the project, generates the artifacts, and deploys them to the specified repository defined in the distributionManagement section of your project’s pom.xml file. This command is commonly used for sharing project artifacts with others and making them available for use in other projects. Proper authentication and access privileges are required for successful deployment. Use it carefully as it publishes your artifacts publicly.

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Your Project Name
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 10 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 20 source files to /path/to/project/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non-existing resourceDirectory /path/to/project/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) ---
[INFO] Building jar: /path/to/project/target/project-name-1.0.0.jar
[INFO] 
[INFO] --- maven-deploy-plugin:3.1.0:deploy (default-deploy) ---
[INFO] Uploading to your-remote-repository: https://your-remote-repository.com/repository/project-name/com/example/project-name/1.0.0/project-name-1.0.0.jar
[INFO] Uploaded to your-remote-repository: https://your-remote-repository.com/repository/project-name/com/example/project-name/1.0.0/project-name-1.0.0.jar (10 KB at 2.5 KB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.123 s
[INFO] Finished at: 2023-07-04T12:34:56Z
[INFO] ------------------------------------------------------------------------

mvn -U or -mvn –update-snapshots

The mvn -U command, or mvn –update-snapshots, is used to force Maven to update the dependencies from remote repositories, even if they are already cached locally. It ensures that the latest versions of the dependencies are retrieved.

We can use this option along with all Maven phases like mvn -U clean compile , mvn -U install etc.

$ mvn -U clean compile
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.6.5/spring-boot-starter-parent-2.6.5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.6.5/spring-boot-starter-parent-2.6.5.pom (8.6 kB at 12 kB/s)
------------------
------------------
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/2.6.5/spring-boot-maven-plugin-2.6.5.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/2.6.5/spring-boot-maven-plugin-2.6.5.pom (4.0 kB at 11 kB/s)
---------------
---------------
Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot/2.6.5/spring-boot-2.6.5.jar (1.4 MB at 399 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/kafka/kafka-clients/3.0.1/kafka-clients-3.0.1.jar (4.9 MB at 1.1 MB/s)
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo ---
[INFO] Deleting <project_directory>/target
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to <project_directory>/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  19.808 s
[INFO] Finished at: 2023-07-04T09:51:34+05:30
[INFO] ------------------------------------------------------------------------

mvn -o or mvn –offline

We can use the option -o or –offline for enabling offline mode. In this mode, Maven will retrieve all the dependencies from the local repository, it will not connect to the remote repository for retreiving the latest dependencies.

We can use the offline option with all the Maven phases like mvn -o clean compile, mvn -o install etc.

$ mvn -o clean compile
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo ---
[INFO] Deleting <project_directory>/target
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to <project_directory>/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.379 s
[INFO] Finished at: 2023-07-04T09:55:18+05:30
[INFO] ------------------------------------------------------------------------

mvn -DskipTests

We can use the option -DskipTests to skip the execution of the tests. Please note that the test source code will be compiled, just that the tests will not run.

$ mvn install -DskipTests
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory <project_directory>/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:3.2.2:jar (default-jar) @ demo ---
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.6.5:repackage (repackage) @ demo ---
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ demo ---
[INFO] Installing <project_directory>/target/demo-0.0.1-SNAPSHOT.jar to <m2_directory>/.m2/repository/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-SNAPSHOT.jar
[INFO] Installing <project_directory>/pom.xml to <m2_directory>/.m2/repository/com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.362 s
[INFO] Finished at: 2023-07-04T09:57:48+05:30
[INFO] ------------------------------------------------------------------------

mvn -Dmaven.test.skip =true

When we use -Dmaven.test.skip =true option, test source code will not be compiled and also tests will not run.

mvn verify -Dmaven.test.skip=true
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:3.2.2:jar (default-jar) @ demo ---
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.6.5:repackage (repackage) @ demo ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.242 s
[INFO] Finished at: 2023-07-04T10:06:40+05:30
[INFO] ------------------------------------------------------------------------

mvn dependency:tree

It shows the dependencies in a hierarchical structure.

$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:3.2.0:tree (default-cli) @ demo ---
[INFO] com.example:demo:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.6.5:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:2.6.5:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.6.5:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.6.5:compile
[INFO] |  |  +- ch.qos.logback:logback-classic:jar:1.2.11:compile
[INFO] |  |  |  \- ch.qos.logback:logback-core:jar:1.2.11:compile
[INFO] |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.17.2:compile
[INFO] |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.17.2:compile
[INFO] |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.36:compile
[INFO] |  +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] |  +- org.springframework:spring-core:jar:5.3.17:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.3.17:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.29:compile
[INFO] +- org.apache.kafka:kafka-streams:jar:3.0.1:compile
[INFO] |  +- org.apache.kafka:kafka-clients:jar:3.0.1:compile
[INFO] |  |  +- com.github.luben:zstd-jni:jar:1.5.0-2:runtime
[INFO] |  |  +- org.lz4:lz4-java:jar:1.7.1:runtime
[INFO] |  |  \- org.xerial.snappy:snappy-java:jar:1.1.8.1:runtime
[INFO] |  +- org.rocksdb:rocksdbjni:jar:6.19.3:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.36:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.13.2:runtime
[INFO] |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.13.2:runtime
[INFO] |     \- com.fasterxml.jackson.core:jackson-core:jar:2.13.2:runtime
[INFO] +- org.springframework.kafka:spring-kafka:jar:2.8.4:compile
[INFO] |  +- org.springframework:spring-context:jar:5.3.17:compile
[INFO] |  |  +- org.springframework:spring-aop:jar:5.3.17:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:5.3.17:compile
[INFO] |  |  \- org.springframework:spring-expression:jar:5.3.17:compile
[INFO] |  +- org.springframework:spring-messaging:jar:5.3.17:compile
[INFO] |  +- org.springframework:spring-tx:jar:5.3.17:compile
[INFO] |  +- org.springframework.retry:spring-retry:jar:1.3.2:compile
[INFO] |  \- com.google.code.findbugs:jsr305:jar:3.0.2:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.6.5:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.6.5:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.6.5:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.6.0:test
[INFO] |  |  \- net.minidev:json-smart:jar:2.4.8:test
[INFO] |  |     \- net.minidev:accessors-smart:jar:2.4.8:test
[INFO] |  |        \- org.ow2.asm:asm:jar:9.1:test
[INFO] |  +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:test
[INFO] |  |  \- jakarta.activation:jakarta.activation-api:jar:1.2.2:test
[INFO] |  +- org.assertj:assertj-core:jar:3.21.0:test
[INFO] |  +- org.hamcrest:hamcrest:jar:2.2:test
[INFO] |  +- org.junit.jupiter:junit-jupiter:jar:5.8.2:test
[INFO] |  |  +- org.junit.jupiter:junit-jupiter-params:jar:5.8.2:test
[INFO] |  |  \- org.junit.jupiter:junit-jupiter-engine:jar:5.8.2:test
[INFO] |  |     \- org.junit.platform:junit-platform-engine:jar:1.8.2:test
[INFO] |  +- org.mockito:mockito-core:jar:4.0.0:test
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.11.22:test
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.11.22:test
[INFO] |  |  \- org.objenesis:objenesis:jar:3.2:test
[INFO] |  +- org.mockito:mockito-junit-jupiter:jar:4.0.0:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-test:jar:5.3.17:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.8.4:test
[INFO] \- org.springframework.kafka:spring-kafka-test:jar:2.8.4:test
[INFO]    +- org.apache.zookeeper:zookeeper:jar:3.6.3:test
[INFO]    |  +- org.apache.zookeeper:zookeeper-jute:jar:3.6.3:test
[INFO]    |  +- org.apache.yetus:audience-annotations:jar:0.5.0:test
[INFO]    |  +- io.netty:netty-handler:jar:4.1.75.Final:test
[INFO]    |  |  +- io.netty:netty-common:jar:4.1.75.Final:test
[INFO]    |  |  +- io.netty:netty-resolver:jar:4.1.75.Final:test
[INFO]    |  |  +- io.netty:netty-buffer:jar:4.1.75.Final:test
[INFO]    |  |  +- io.netty:netty-transport:jar:4.1.75.Final:test
[INFO]    |  |  \- io.netty:netty-codec:jar:4.1.75.Final:test
[INFO]    |  \- io.netty:netty-transport-native-epoll:jar:4.1.75.Final:test
[INFO]    |     +- io.netty:netty-transport-native-unix-common:jar:4.1.75.Final:test
[INFO]    |     \- io.netty:netty-transport-classes-epoll:jar:4.1.75.Final:test
[INFO]    +- org.apache.kafka:kafka-clients:jar:test:3.0.1:test
[INFO]    +- org.apache.kafka:kafka-metadata:jar:3.0.1:test
[INFO]    |  +- org.apache.kafka:kafka-server-common:jar:3.0.1:test
[INFO]    |  +- org.apache.kafka:kafka-raft:jar:3.0.1:test
[INFO]    |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.13.2:test
[INFO]    |  \- com.yammer.metrics:metrics-core:jar:2.2.0:test
[INFO]    +- org.apache.kafka:kafka-streams-test-utils:jar:3.0.1:test
[INFO]    +- org.apache.kafka:kafka_2.13:jar:3.0.1:test
[INFO]    |  +- org.scala-lang:scala-library:jar:2.13.6:test
[INFO]    |  +- org.apache.kafka:kafka-storage:jar:3.0.1:test
[INFO]    |  |  \- org.apache.kafka:kafka-storage-api:jar:3.0.1:test
[INFO]    |  +- net.sourceforge.argparse4j:argparse4j:jar:0.7.0:test
[INFO]    |  +- com.fasterxml.jackson.module:jackson-module-scala_2.13:jar:2.13.2:test
[INFO]    |  |  \- com.thoughtworks.paranamer:paranamer:jar:2.8:test
[INFO]    |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-csv:jar:2.13.2:test
[INFO]    |  +- net.sf.jopt-simple:jopt-simple:jar:5.0.4:test
[INFO]    |  +- org.scala-lang.modules:scala-collection-compat_2.13:jar:2.4.4:test
[INFO]    |  +- org.scala-lang.modules:scala-java8-compat_2.13:jar:1.0.0:test
[INFO]    |  +- org.scala-lang:scala-reflect:jar:2.13.6:test
[INFO]    |  +- com.typesafe.scala-logging:scala-logging_2.13:jar:3.9.3:test
[INFO]    |  +- io.dropwizard.metrics:metrics-core:jar:4.2.9:test
[INFO]    |  \- commons-cli:commons-cli:jar:1.4:test
[INFO]    +- org.apache.kafka:kafka_2.13:jar:test:3.0.1:test
[INFO]    \- org.junit.jupiter:junit-jupiter-api:jar:5.8.2:test
[INFO]       +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO]       +- org.junit.platform:junit-platform-commons:jar:1.8.2:test
[INFO]       \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.041 s
[INFO] Finished at: 2023-07-04T10:08:07+05:30
[INFO] ------------------------------------------------------------------------

mvn dependency:list

It displays the project’s dependencies in a flat, alphabetically-sorted list.

$ mvn dependency:list
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:3.2.0:list (default-cli) @ demo ---
[INFO] 
[INFO] The following files have been resolved:
[INFO]    org.springframework.boot:spring-boot-starter:jar:2.6.5:compile -- module spring.boot.starter [auto]
[INFO]    org.springframework.boot:spring-boot:jar:2.6.5:compile -- module spring.boot [auto]
[INFO]    org.springframework:spring-context:jar:5.3.17:compile -- module spring.context [auto]
[INFO]    org.springframework:spring-aop:jar:5.3.17:compile -- module spring.aop [auto]
[INFO]    org.springframework:spring-beans:jar:5.3.17:compile -- module spring.beans [auto]
[INFO]    org.springframework:spring-expression:jar:5.3.17:compile -- module spring.expression [auto]
[INFO]    org.springframework.boot:spring-boot-autoconfigure:jar:2.6.5:compile -- module spring.boot.autoconfigure [auto]
[INFO]    org.springframework.boot:spring-boot-starter-logging:jar:2.6.5:compile -- module spring.boot.starter.logging [auto]
[INFO]    ch.qos.logback:logback-classic:jar:1.2.11:compile -- module logback.classic (auto)
[INFO]    ch.qos.logback:logback-core:jar:1.2.11:compile -- module logback.core (auto)
[INFO]    org.slf4j:slf4j-api:jar:1.7.36:compile -- module org.slf4j [auto]
[INFO]    org.apache.logging.log4j:log4j-to-slf4j:jar:2.17.2:compile -- module org.apache.logging.slf4j [auto]
[INFO]    org.apache.logging.log4j:log4j-api:jar:2.17.2:compile -- module org.apache.logging.log4j
[INFO]    org.slf4j:jul-to-slf4j:jar:1.7.36:compile -- module jul.to.slf4j (auto)
[INFO]    jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile -- module java.annotation [auto]
[INFO]    org.springframework:spring-core:jar:5.3.17:compile -- module spring.core [auto]
[INFO]    org.springframework:spring-jcl:jar:5.3.17:compile -- module spring.jcl [auto]
[INFO]    org.yaml:snakeyaml:jar:1.29:compile -- module org.yaml.snakeyaml [auto]
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.115 s
[INFO] Finished at: 2023-07-04T10:10:37+05:30
[INFO] ------------------------------------------------------------------------

mvn -T <arg> or mvn —threads <arg>

We can use the option -T or –threads and specify the number of threads for executing the Maven command.

For example :
mvn -T 4 clean compile -> This uses 4 threads
mvn -T 1C clean compile -> This uses 1 thread per cpu core
mvn -T 1.5C clean compile -> This uses 1.5 thread per cpu core

$ mvn -T 4 clean compile
[INFO] Scanning for projects...
[INFO] 
[INFO] Using the MultiThreadedBuilder implementation with a thread count of 4
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo ---
[INFO] Deleting <project_directory>/target
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to <project_directory>/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.014 s (Wall Clock)
[INFO] Finished at: 2023-07-04T10:12:13+05:30
[INFO] ------------------------------------------------------------------------

Conclusion

In conclusion, this article provided an overview of the top Maven commands commonly used in software development projects. Each command was explained with examples and demonstrated by executing them in the terminal. Understanding these Maven commands is essential for effectively managing and building Java projects using Maven.

For a more comprehensive understanding of Docker Commands, you can refer Docker Commands.

Leave a Reply

Your email address will not be published. Required fields are marked *