Find pom in subdirectories and execute mvn clean

What is the command to search all subdirectories containing the pom.xml file and then execute: mvn clean in this subdirectory?

I have workspaces that contain several maven projects and I want to clear all of them

+6
source share
3 answers

Perhaps something like this should work:

to find. -name "pom.xml" -exec mvn clean -f '{}' \;

+24
source

in general, you would like to release mvn clean on the parent pom, which will also clean up all children defined as modules.

If you don’t have and don’t need such a parent, you need to use brute force for this, which means something like

 for dir in yourdirectory; do cd $dir if [ -f pom.xml ]; then mvn clean fi done 
+2
source

I use this script, it calls mvn clean only those projects that need to be cleaned (they have a target directory):

 find . -name "target" -type d \ | sed s/target/pom.xml/ \ | tee /dev/stderr \ | xargs -I {} mvn -q clean -f {} 

The tee part is optional, it just prints the cleaned project.

+1
source

All Articles