Sunday, 13 March 2022

mvn clean: clean all the build artefacts

‘mvn clean’ command delete all the build artifacts.

 

Let’s confirm the same from below example.

 

Step 1: Download the project ‘hello-world-eclipse’

https://github.com/harikrishna553/java-libs/tree/master/maven-projects/hello-world-eclipse

 

Step 2: Navigate to the directory where pom.xml is located, execute the command ‘mvn clean package’.

$mvn clean package
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------< com.sample.app:hello-world-eclipse >-----------------
[INFO] Building hello-world-eclipse 1
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/3.0.2/maven-jar-plugin-3.0.2.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/3.0.2/maven-jar-plugin-3.0.2.jar (0 B at 0 B/s)
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hello-world-eclipse ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hello-world-eclipse ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ hello-world-eclipse ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/krishna/eclipse-workspace/hello-world-eclipse/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ hello-world-eclipse ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ hello-world-eclipse ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ hello-world-eclipse ---
[INFO] 
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ hello-world-eclipse ---
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/3.0.1/maven-shared-utils-3.0.1.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/3.0.1/maven-shared-utils-3.0.1.jar (0 B at 0 B/s)
[INFO] Building jar: /Users/krishna/eclipse-workspace/hello-world-eclipse/target/hello-world-eclipse-1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.247 s
[INFO] Finished at: 2022-03-13T19:52:26+05:30
[INFO] ------------------------------------------------------------------------
$

 


Once the command executed successfully, you can observe that the build artefacts are created in target folder.

$ls
pom.xml	src	target
$
$ls target/
classes				hello-world-eclipse-1.jar	maven-status
generated-sources		maven-archiver			test-classes

 

When you execute ‘mvn clean’ command, target folder will be deleted.

$mvn clean
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------< com.sample.app:hello-world-eclipse >-----------------
[INFO] Building hello-world-eclipse 1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ hello-world-eclipse ---
[INFO] Deleting /Users/krishna/eclipse-workspace/hello-world-eclipse/target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.190 s
[INFO] Finished at: 2022-03-13T20:14:25+05:30
[INFO] ------------------------------------------------------------------------

 

You can confirm the same by printing the contents of hellow-world-eclipse project.

$ls
pom.xml	src

 

 

 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment