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):

project
|------->pom.xml
|------->subproject1
|------->pom.xml
|------->folder1
|------->pom.xml
|------->subproject2
|------->pom.xml
|------->folder2
|------->pom.xml
|------->subproject3
|------->pom.xml
|------->folder3
|------->pom.xml
|------->subproject4
|------->pom.xml
|------->folder4
|------->pom.xml
|------->subproject5
|------->pom.xml
|------->folder5
|------->pom.xml


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

MVN_ARTIFACTID=$(mvn -q \
-Dexec.executable="echo" \
-Dexec.args='${project.artifactId}' \
--non-recursive \
org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)


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

Thanks.

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.

Module-1
Module-2
Module-3
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download