与孩子一起阅读POM [英] Reading POM's with its children

查看:74
本文介绍了与孩子一起阅读POM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于帖子提到(通过Brett Porter)可以读取POM.我需要的不仅是阅读一首pom.我需要在多模块构建中阅读pom的整个树.从root pom开始,如果可能,它应该自动读取子pom的内容?我需要在与Maven本身无关的单独Java代码中执行此操作.

Based on the post it is mentioned (By Brett Porter) that a POM can be read. What i need is to read not only a single pom. I need to read the whole tree of pom's in a multimodule build. Starting with the root pom and it should read automatically the child pom's if it's possible? I need to do this in separate Java Code not in relationship with Maven itself.

推荐答案

也许这有点作弊,但也许您可以通过Runtime.exec(

Perhaps this is cheating a small bit, but perhaps you could call mvn help:effective-pom on the parent pom through Runtime.exec (http://java.sun.com/javase/6/docs/api/java/lang/Runtime.html#exec%28java.lang.String%29), which will give you the congolemerate pom file of the target pom you called it on when combined with its parents and modules. That will give you a single pom file to work with and prevent you have having to discover modules / parents yourself.

我对Maven库本身还不太熟悉,以至于我知道如何在不以其他方式启动Maven的情况下本地生成有效的pom,尽管我无法想象这是不可能的.如果有机会看的话,我会照做的,并据此编辑答案.

I'm not familiar enough with the maven libraries themselves to know how to generate an effective pom natively without starting maven in another process, although I can't imagine that not being possible. If I get a chance to look, I'll do so and edit my answer accordingly.

这是指向EffectivePomMojo源代码的链接,该源代码显示help:effective-pom如何生成该xml:

Here's a link to the EffectivePomMojo source code that shows how help:effective-pom is generating that xml: http://svn.apache.org/viewvc/maven/plugins/tags/maven-help-plugin-2.1.1/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java?view=markup. Hope that helps... although I'm not familiar with how that mojo is getting its MavenProject object or the List of MavenProject objects that have private scope.

这篇关于与孩子一起阅读POM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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