Search code examples
bashmavenxargs

How to pass a result of find command to the mvn command using xargs?


Note: I don't want to use find ... exec ... because in this way maven errors are ignored.

I am trying to find all pom.xml within given folder and execute mvn on them. But I have an issue with proper passing find results to the xargs function. This:

find ./maven_projects -name 'pom.xml' -print0 | xargs -0 mvn clean package -f

is not working. I receive kind of this error in maven:

[ERROR] Unknown lifecycle phase "./maven_projects/project1/pom.xml"


Solution

  • I have found how to solve it. The trick is to wrap a filename into an argument and pass it as this:

    find ./maven_projects -name 'pom.xml' -print0 | xargs -0 -L 1 sh -c 'mvn -f "$0" clean package'