如何显示Maven POM层次结构? [英] How do I show the Maven POM hierarchy?

查看:380
本文介绍了如何显示Maven POM层次结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做脚本,我需要获取任何给定pom的所有父pom的列表.依赖插件似乎只对pom的依赖部分中列出的依赖感兴趣,但是似乎没有办法显示父poms,这也是Maven正常工作所必需的依赖. >

我缺少基本的东西吗?

解决方案

没有简单的Maven命令向您显示pom.xml的父POM链.这样做的原因是,这不是一个通常会问到的常见问题(更多信息请参见下文).对于您的脚本,您只需要解析pom.xml文件,获取父工件的坐标,获取工件的pom.xml文件的内容,然后解析它的pom.xml文件(并重复).抱歉,但是我没有捷径可走,但是其他人也解决了类似的问题.

从技术上来说是正确的,父pom是项目的依赖项,但这不是字面的Maven依赖项,并且处理方式完全不同.父poms链,活动配置文件,您的settings.xml文件以及安装目录中的Maven超级pom都组合在一起,以创建项目的有效pom .有效的POM是Maven真正用来完成其工作的工具.因此,基本上,父pom继承链已经被解析并合并,甚至在依赖项插件(或任何其他插件)被激活之前.

大多数人通常会问的问题是:当Maven完成所有内容的组合后,我真正的pom.xml 真的会是什么样?"或我的父母poms的继承链有什么结果?"或活动配置文件如何影响我的pom.xml属性?"有效的pom会告诉您所有这一切.

我知道您没有要求,但是对于其他阅读此文件的人,如果您想查看您的父pom.xml,只需在M2Eclipse POM编辑器中打开pom.xml,然后单击概述上的父工件链接即可.标签.这样,您只需单击一次pom即可快速向上移动pom.xml文件链.这将是一个奇怪的项目,它具有超过3或4个父继承项.

如果要查看有效的pom,可以运行命令mvn help:effective-pom.或者,您可以在M2Eclipse的POM编辑器中单击有效POM"选项卡.

I'm doing some scripting and I need to get a list of all the parent poms for any given pom. The dependency plugin seems to be only interested in the dependencies that are listed in the dependency section of the pom, but there doesn't seem to be a way to show the parent poms, which are also required dependencies for Maven to work.

Am I missing something basic?

解决方案

There is no simple Maven command that will show you the chain of parent POMs for a pom.xml. The reason for this is that it is not a common question one would typically ask (more on that below). For your script, you'll just have to parse the pom.xml file, get the parent artifact coordinates, get a hold of the artifact's pom.xml file and then parse it's pom.xml file (and repeat). Sorry, but there is no short cut I know of, but other folks have solved similar problems.

You are right that technically the parent pom is a dependency of your project, but it is not a literal Maven Dependency and is handled completely differently. The chain of parent poms, along with active profiles, your settings.xml file, and the Maven super pom from the installation directory are all combined together to create your project's effective pom. The effective POM is what Maven really uses to do its work. So basically, the parent pom inheritance chain is already resolved and combined before the dependency plugin (or any other plugin) is even activated.

The questions most people typically ask is 'what does my REAL pom.xml really look like when Maven is done combining everything?' or 'What is the result my inheritance chain of parent poms?' or 'How are my pom.xml properties affected by an active profile?' The effective pom will tell you all of this.

I know you didn't ask, but for others reading this, if you want to see your parent pom.xml, simply open up the pom.xml in the M2Eclipse POM editor and click on the parent artifact link on the overview tab. In this way you can quickly move up the chain of pom.xml files with just a single click per pom. It would be a strange project that had more than 3 or 4 parent poms of inheritance.

If you want to see your effective pom, you can run the command mvn help:effective-pom. Alternatively, you can click on the Effective POM tab in M2Eclipse's POM editor.

这篇关于如何显示Maven POM层次结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆