Hi Sandra,

first question: Do you need the full resolved pom (effective pom) or would it be enough just to simply to parse the pom file which can simply being done using MavenXpp3Reader this would deliver the XML as a Maven Model class which can simply being used to extract information from the maven model...

Kind regards
Karl Heinz Marbaise

On 09/08/17 13:00, spars...@web.de wrote:
Hello,

currently, I'm working on a small tool, that needs some information of a POM 
and its parent POM. I didn't want to parse them with a XML reader, so I found 
that the DefaultModelBuilder can build a complete effective POM for me. Based 
on a stackoverflow answer 
(https://stackoverflow.com/questions/27383357/how-do-i-instantiate-mavenresolver-for-modelbuilder-usage)
  I build following example:

DefaultModelBuilderFactory factory = new DefaultModelBuilderFactory();
  final DefaultModelBuilder defaultModelBuilder = factory.newInstance();
  ModelBuildingRequest buildRequest = new DefaultModelBuildingRequest();
  buildRequest.setPomFile(Paths.get("/path/to/a/pom.xml").toFile())
          .setProcessPlugins(false)
          .setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
  final ModelBuildingResult modelBuildingResult = 
defaultModelBuilder.build(buildRequest);

It works fine for simple POM (simple means a POM without a parent reference). But if I set a POM with a parent reference in buildRequest.setPomFile, I get following exception:

Exception in thread "main" java.lang.IllegalArgumentException: no model 
resolver provided, cannot resolve parent POM groupId:artifactId:1 for POM 
groupId:artifactId:version (/path/to/a/pom.xml)
  at 
org.apache.maven.model.building.DefaultModelBuilder.readParentExternally(DefaultModelBuilder.java:890)
  at 
org.apache.maven.model.building.DefaultModelBuilder.readParent(DefaultModelBuilder.java:750)
  at 
org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:309)
  at 
com.github.sparsick.maven.effecitve.pom.maven.model.builder.ApacheMavenModelBuilder.main(ApacheMavenModelBuilder.java:17)

Another example on Stackoverflow 
(https://stackoverflow.com/questions/4838591/is-there-a-library-for-reading-maven2-3-pom-xml-files)
 mentions to use RepositoryModelResolver from Apache Archiva as an 
implementation ModelResolver. But I don't want to introduce a dependency to 
Apache Archiva in my tool.

So my questions are, is the usage of DefaultModelBuilder the best way to get an 
effective POM of my project outside of a Maven Plugin? If so which 
implementation I should use for the ModelResolver? If not what is the best way 
to get the effective POM outside of a Maven Plugin.

Thank you and best regards,

Sandra Parsick

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org

Reply via email to