Reading POM with your kids

Based on the post, it is mentioned (by Brett Porter) that the POM is readable. What I need is to read more than just one pom. I need to read the entire pom tree in a multi-module assembly. Starting at the root pump and should it automatically read the baby if possible? I need to do this in separate Java code, not relevant to Maven itself.

+2


a source to share


2 answers


Perhaps this changes a little, but perhaps you could call mvn help:effective-pom

on the parent pom via 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 target pom file that you named in combination with the parents and modules. This will give you one pom file to work with and prevent you from having to discover modules / parents yourself.

I don't know enough about the maven libraries themselves to know how to create efficient raw data without starting maven in another process, although I can't imagine that this is impossible. If I get a chance to look, I will do so and edit my answer accordingly.



[change]

Here's a link to the EffectivePomMojo source code that shows how help: effective-pom generates 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 this helps ... although I'm not familiar with how this mojo gets its MavenProject object or MavenProject list objects that have a private scope.

+1


a source


I want to say that you want to do this without maven. Trying to do this without any dependency on maven or in particular maven libraries like maven-model, maven-project-builder will require a lot of rethinking of the already existing code. You can read the POM and extract data from it without doing a full maven build.

The Artifactory source code contains some useful pointers such as using



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

      

Read into maven pom and get the model. The model has addModule and getModules () method. You can use this to find child pumps relative to the current parent pump.

+2


a source







All Articles