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.
-
@khmarbaise can you tell me what benefit would you gain from reading pom and not executing it? – ant May 18 '10 at 07:28
-
I have a project which is a combination of Make/CMake/Maven and i need to read the dependency information of the Java projects. I know that this is not the best way. I would be the first who like to change that, but at the moment i have no choice. – khmarbaise May 18 '10 at 07:57
2 Answers
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.

- 56,943
- 12
- 94
- 128
-
Ah sorry...so my question was not accurate enough. Of course i can use Maven libraries. The thing i can't do is to let Maven do the work...i need the dependencies of the modules etc. But your hint is very good...Thanks. – khmarbaise May 18 '10 at 10:49
-
@mdma The given link is broken can you please update it ASAP – Kasun Siyambalapitiya Jun 23 '17 at 13:31
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.

- 16,075
- 10
- 57
- 68
-
No i can't call mvn help:effective-pom ...I need to do this in Java Code...without exec calling. – khmarbaise May 18 '10 at 17:08