Re: Dynamically modifying MavenProject.getModel() so that sub-sequent lifecycle phases can pick up those changes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Dynamically modifying MavenProject.getModel() so that sub-sequent lifecycle phases can pick up those changes

stephenconnolly
On Mon 18 Dec 2017 at 18:10, Romain Manni-Bucau <[hidden email]>
wrote:

> Hi
>
> Did you try writing an extension instead of a mojo? It does exactly that (+
> few other things)
>
> Le 18 déc. 2017 19:03, "Quijada, Jose M" <[hidden email]> a
> écrit :
>
> > I would like to write a Maven plugin that among other things manipulates
> > (both add/update) the POM model available at MavenProjects.getModel()
> while
> > executing Maven phase goals, such as "test" and "site", so that for
> > instance I can:
> >
> > 1) Add a <reporting/> node along with plugins inside, so that when the
> > "site" phase runs, those plugins can be used to generate reports
> > 2) On the fly add plugins to <build/>, along with <executions/> for those
> > plugins, so that they run as part of other phases.
> > 3) Fro plugins that are already in the POM model, update things like
> > versions, <executions/>.
> >
> >
> > I already wrote the plugin, and wrote Java code to make the necessary
> > additions/update to the POM. I've injected MavenProject into my Mojo via
> > @Parameter(defaultValue = "${project}")
> >
> > private MavenProject project;
> >
> >
> > But those additions/changes to the POM Model object are being ignored.
> > For exaxample,
> >
> > one use case I have is to tack on <reporting/> with a bunch of plugins
> >
> > and reports they should generate. I execute my custom logic as part of
> >
> > the pre-site face (I create a Mojo and configured its goal to run with
> > pre-site). Then n
> >
> > in the code of the Mojo I do the additions/updates to the POM. But
> > when "site" phase runs,
> >
> > the reports added to the POM not executing.
> >
> >
> > Am I missing something fundamental about Maven POM? Are modifications
> > to POM at runtime


As of Maven 3.3.0 the model is no longer run-time mutable.

I am not entirely happy with this as is causes issues for the shade plugin
among other things, but there are good reasons for the model to be
restrictive in what changes are allowed *after* the build plan has been
determined.

>
> >
> > not allowed? I suspect this is the reason, but I wanted to confirmed with
> >
> > more experienced Maven developers.
> >
> >
> > Thank you, and let me know what other details I can provide to clarify
> > things.
> >
> >
> >
> > Best,
> >
> > Jose.
> >
>
--
Sent from my phone