bash 在子目录中找到 pom 并执行 mvn clean

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15895805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:08:50  来源:igfitidea点击:

Find pom in subdirectories and execute mvn clean

bashmaven

提问by Damian0o

What is the command for finding all subdirectories which contains pom.xml file and then execute: mvn clean operation in that subdirectory ?

查找包含 pom.xml 文件的所有子目录然后在该子目录中执行 mvn clean operation 的命令是什么?

I have workspaces whose contains multiple maven project and i want to clean all of them

我有包含多个 maven 项目的工作区,我想清理所有这些

回答by Mzzl

Something like this should probably work:

像这样的事情应该可以工作:

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

找 。-name "pom.xml" -exec mvn clean -f '{}' \;

回答by eis

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

通常,您会希望mvn clean在父 pom上发出问题,这也将清除定义为模块的所有子项。

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

回答by juzraai

I am using this script, it calls mvn cleanonly on those projects that have to be cleaned (they have a targetdirectory):

我正在使用这个脚本,它只调用mvn clean那些必须清理的项目(它们有一个target目录):

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

The teepart is optional, it just prints out the project that is being cleaned.

tee部分是可选的,它只是打印出正在清理的项目。