使用 xmstarlet 从 maven pom.xml 中找到特定的 groupId

find a specific groupId from a maven pom.xml using xmstarlet

我正在尝试使用 xmlstarlet 从 Maven POM.XML 中找到特定的 groupId 和 artifactId,但没有成功。 这是我正在使用的命令:

xmlstarlet sel -N pom=http://maven.apache.org/POM/4.0.0 -t \
     -m "/pom:project/pom:dependencyManagement/pom:dependencies/pom:dependency[.//pom:groupId=com.mygroup.xxx]" \ 
     -v '.' pom.xml 

感谢任何帮助。

编辑:感谢npostavs,对于有同样问题的其他人,也可以组合更多的表达式并根据更多的元素过滤结果:

  xmlstarlet sel -N pom=http://maven.apache.org/POM/4.0.0 -t -m "/pom:project/pom:dependencyManagement/pom:dependencies/dependency[.//pom:groupId='com.mygroup.xxx'][.//pom:artifactId='myartifact-xxx']" -v '.' pom.xml

pom:groupId=com.mygroup.xxx

您需要在字符串文字周围加上引号:pom:groupId='com.mygroup.xxx',否则它会查找名为 com.mygroup.xxx.

的 XML 个元素