You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by "Quijada, Jose M" <jo...@verizon.com> on 2017/12/18 18:02:56 UTC

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

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

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.

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

Posted by "Quijada, Jose M" <jo...@verizon.com>.
I know it's been over a year since I posted this question, but just wanted
to say thanks. Using Maven plugin extensions to develop my plugin worked
like a charm. I implemented
com.exsoinn.maven.plugin.CodeQualityMavenLifecycleParticipant#afterProjectsRead
hook to programmatically modify the Maven project right after it gets
read.. The project, still in its infancy, yet it is a working version, can
be found here <https://github.com/joquijada/code-quality-maven-plugin>.

I was able to use the newly developed plugin successfully on another
project I have <https://github.com/joquijada/element-path-finder>. The site
and reports generated by my plugin for that project can be found here
<https://joquijada.github.io/element-path-finder/site-epf/>.

On Mon, Dec 18, 2017 at 2:32 PM Stephen Connolly <
stephen.alan.connolly@gmail.com> wrote:

> On Mon 18 Dec 2017 at 18:10, Romain Manni-Bucau <rm...@gmail.com>
> 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" <jo...@verizon.com> 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
>

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

Posted by Stephen Connolly <st...@gmail.com>.
On Mon 18 Dec 2017 at 18:10, Romain Manni-Bucau <rm...@gmail.com>
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" <jo...@verizon.com> 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

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

Posted by Romain Manni-Bucau <rm...@gmail.com>.
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" <jo...@verizon.com> 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
>
> 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.
>