开发者

Reading POM's with its children

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.


I mention you want to do this without maven. Trying to do this without any reliance on maven, or particularly the maven libraries like maven-model, maven-project-builder, will involve a lot of reinvention of already existing code. You can read POMs and extract data from them without doing a full maven build.

The source code from Artifactory has some useful pointers, such as using

MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new InputStreamReader(in, "utf-8"));

To read in a maven pom and get the model. The Model has a method addModule, and getModules(). You can use this to locate child poms relative to the current parent pom.


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.

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.

[Edit]

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜