Damian0o
Damian0o

Reputation: 653

Find pom in subdirectories and execute mvn clean

What is the command for finding all subdirectories which contain pom.xml file and then execute:

mvn clean 

operation in that subdirectory?

I have workspaces that contain multiple maven projects and I want to clean all of them.

Upvotes: 22

Views: 9522

Answers (4)

user1961312
user1961312

Reputation: 159

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

put this in a file like 'cleanRepo.sh'

execute in unix-terminal or on windows within git-bash:

sh cleanRepo.sh

for me this works best since i only work with multi-module-projects.

Upvotes: 3

Mzzl
Mzzl

Reputation: 4126

Something like this should probably work:

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

Upvotes: 49

juzraai
juzraai

Reputation: 5943

I am using this script, it calls mvn clean only on those projects that have 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 out the project that is being cleaned.

Upvotes: 4

eis
eis

Reputation: 53482

in general, you would want to issue mvn clean on the parent pom, which would clean all children defined as modules, too.

If you don't have and don't want such a parent you'll need to use brute force for this, meaning something like

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

Upvotes: 3

Related Questions