3

I'm creating an addon that programmatically updates the existing POM, I'm able to add dependencies, repository, and various other information using DependencyFacet, MavenFacet etc., However, I'm unable to figure out how to add a parent POM. Following is the code I tried and it didn't work. Any help is appreciated as to which facet I can use and what is the syntax to use it.

 Parent p = new Parent();
 p.setGroupId("org.example");
 p.setArtifactId("application-master-pom");
 p.setVersion("1.1.0");
 MavenFacet mavenFacet = getFaceted().getFacet(MavenFacet.class);
 mavenFacet.getModel().setParent(p);

However the parent POM reference is not being added to the project pom on which the command I'm creating is executed.

Buddha
  • 4,339
  • 2
  • 27
  • 51
  • In which way would you like to update the pom ? Versions? – khmarbaise Apr 11 '15 at 13:01
  • I'm trying to use MavenFacet to programatically update the POM but not sure it is the right one. – Buddha Apr 11 '15 at 14:32
  • The facet are IDE specific which is done by importing a project into Eclipse and apart from that it does not make sense to put such things into your pom and they do not belong there. Which Eclipse / IDE do you use? – khmarbaise Apr 11 '15 at 15:46
  • @khmarbaise I'm not sure if you are aware of jboss forge and its framework. I'm building an addon for jboss forge, where there are several facets or utilities available. That can be used to do several things. MavenFacet helps up do several things with Maven POMs. DependencyFacet for adding dependencies to a pom. http://forge.jboss.org/ – Buddha Apr 11 '15 at 16:53

1 Answers1

5

I found the answer after some trial and errors...

Parent p = new Parent();
p.setGroupId("org.codehaus.griffon");
p.setArtifactId("application-master-pom");
p.setVersion("1.0.0");
MavenFacet mavenFacet = getFaceted().getFacet(MavenFacet.class);
Model model = mavenFacet.getModel();
model.setParent(p);
mavenFacet.setModel(model); 

Instead of directly setting parent as in the question. If we get the model and set the parent and reset the model using maven facet, it is successfully updating the parent pom.

Buddha
  • 4,339
  • 2
  • 27
  • 51