简体   繁体   English

如何在多模块项目中(使用Shell脚本)从所有pom.xml文件中提取artifactId?

[英]How to extract the artifactId from all pom.xml files using in a multimodule project (using shell script)?

I need to extract the artifactId from all the poms in a multimodule project. 我需要从多模块项目中的所有pom中提取artifactId。

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. 然后,我将此变量用于Bamboo计划中的其他操作。

How I can do similar tasks with multimodule projects? 如何使用多模块项目执行类似的任务? I need to extract the artifactId of all poms in variables. 我需要提取变量中所有pom的artifactId。

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 我知道这篇文章,但问题不一样: 如何在Shell脚本中从pom.xml文件中提取GAV

Thanks. 谢谢。

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. 添加##作为一个小技巧,以便第二行可以更易读的格式给出artifactId名称。 Else all modules will be echoed in same line. 否则,所有模块将在同一行中回显。

Module-1
Module-2
Module-3

This should do it (adapted from the answer referenced in the question): 应该这样做(改编自问题中引用的答案):

 grep -v '\[' <( find . -type f -name 'pom.xml' -exec mvn -f{} help:evaluate -Dexpression="project.artifactId" \; ) 

Note that the other answer didn't work for me in Maven 3.5.4. 请注意,其他答案在Maven 3.5.4中对我不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM