trisquel trisquel - 3 years ago 217
Bash Question

How to extract the artifactId from a pom.xml file using shell script in a multimodule project?

I need to extract the artifactId from all the poms in a multimodule project.

The project structure is similar to this but the structure can be different (It's depends of the project):


I'm using this command for extract the info in single module projects:

-Dexec.executable="echo" \
-Dexec.args='${project.artifactId}' \
--non-recursive \

Then I use this variable for other actions in a Bamboo Plan.

How I can do similar tasks with multimodule projects? I need to extract the artifactId of all poms in variables.

I know about this post but It's not the same problem:
How to extract the GAV from a pom.xml file in a shell script


Answer Source

Just remove non recursive option :

MVN_ARTIFACTID=$(mvn -q -Dexec.executable="echo" -Dexec.args='${project.artifactId} ##' org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
echo $MVN_ARTIFACTID| sed 's/##/\n/g'

Added ## as a small hack so that second line can give artifactId names in more readable format. Else all modules will be echoed in same line.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download