Preferred way to execute Maven goals/phases from Maven plugins

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

Preferred way to execute Maven goals/phases from Maven plugins

Nick_S
Hi folks,

We are struggling with our buildserver (Jenkins) and the Git-Flow Maven
Plugin[1] with regards to execute the Maven executable to run specific
goals and phases during release (i.e. run versions plugin to change version
or run `mvn verify` to check project).

The gitflow-m-p uses a flag to set the executable which needs to know if it
is on Linux (run mvn) or Windows (run mvn.cmd).

I was wondering what is the 'right' way to execute Maven from a plugin.
I've taken a look at the Maven Release Plugin and that one uses an internal
Executor framework. I have thought about Toolchain, but I didn't find an
example of a toolchain with Maven itself.

Can anyone enlighten me?

[1] https://github.com/aleksandr-m/gitflow-maven-plugin

With regards,

Nick Stolwijk

~~~ Try to leave this world a little better than you found it and, when
your turn comes to die, you can die happy in feeling that at any rate you
have not wasted your time but have done your best ~~~

Lord Baden-Powell
Reply | Threaded
Open this post in threaded view
|

Re: Preferred way to execute Maven goals/phases from Maven plugins

Thomas Broyer-2
Maybe have a look at Maven Invoker:
https://maven.apache.org/shared/maven-invoker/
(it's what the Maven Invoker Plugin and Maven Release Plugin use)

On Mon, Nov 2, 2020 at 11:28 AM Nick Stolwijk <[hidden email]>
wrote:

> Hi folks,
>
> We are struggling with our buildserver (Jenkins) and the Git-Flow Maven
> Plugin[1] with regards to execute the Maven executable to run specific
> goals and phases during release (i.e. run versions plugin to change version
> or run `mvn verify` to check project).
>
> The gitflow-m-p uses a flag to set the executable which needs to know if it
> is on Linux (run mvn) or Windows (run mvn.cmd).
>
> I was wondering what is the 'right' way to execute Maven from a plugin.
> I've taken a look at the Maven Release Plugin and that one uses an internal
> Executor framework. I have thought about Toolchain, but I didn't find an
> example of a toolchain with Maven itself.
>
> Can anyone enlighten me?
>
> [1] https://github.com/aleksandr-m/gitflow-maven-plugin
>
> With regards,
>
> Nick Stolwijk
>
> ~~~ Try to leave this world a little better than you found it and, when
> your turn comes to die, you can die happy in feeling that at any rate you
> have not wasted your time but have done your best ~~~
>
> Lord Baden-Powell
>


--
Thomas Broyer
/tɔ.ma.bʁwa.je/ <http://xn--nna.ma.xn--bwa-xxb.je/>
Reply | Threaded
Open this post in threaded view
|

Re: Preferred way to execute Maven goals/phases from Maven plugins

Nick_S
Thanks,

I looked at the Maven Release Plugin and I see that the logic of where
Maven is installed is not in the Maven-Invoker, but in the release plugin
[1]. There is some logic on how to 'find' Maven, using environment
variables like 'maven.home', 'MAVEN_HOME' and 'M2_HOME'. Does this mean
that the choice of which setting is used and in which order is still the
responsibility of the calling plugin? Or is there some standard for that?

[1]
https://github.com/apache/maven-release/blob/dbdf3a4a8cb8db51fa73963912555be4f39a89b8/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java#L318

With regards,

Nick Stolwijk

~~~ Try to leave this world a little better than you found it and, when
your turn comes to die, you can die happy in feeling that at any rate you
have not wasted your time but have done your best ~~~

Lord Baden-Powell


On Mon, Nov 2, 2020 at 12:27 PM Thomas Broyer <[hidden email]> wrote:

> Maybe have a look at Maven Invoker:
> https://maven.apache.org/shared/maven-invoker/
> (it's what the Maven Invoker Plugin and Maven Release Plugin use)
>
> On Mon, Nov 2, 2020 at 11:28 AM Nick Stolwijk <[hidden email]>
> wrote:
>
> > Hi folks,
> >
> > We are struggling with our buildserver (Jenkins) and the Git-Flow Maven
> > Plugin[1] with regards to execute the Maven executable to run specific
> > goals and phases during release (i.e. run versions plugin to change
> version
> > or run `mvn verify` to check project).
> >
> > The gitflow-m-p uses a flag to set the executable which needs to know if
> it
> > is on Linux (run mvn) or Windows (run mvn.cmd).
> >
> > I was wondering what is the 'right' way to execute Maven from a plugin.
> > I've taken a look at the Maven Release Plugin and that one uses an
> internal
> > Executor framework. I have thought about Toolchain, but I didn't find an
> > example of a toolchain with Maven itself.
> >
> > Can anyone enlighten me?
> >
> > [1] https://github.com/aleksandr-m/gitflow-maven-plugin
> >
> > With regards,
> >
> > Nick Stolwijk
> >
> > ~~~ Try to leave this world a little better than you found it and, when
> > your turn comes to die, you can die happy in feeling that at any rate you
> > have not wasted your time but have done your best ~~~
> >
> > Lord Baden-Powell
> >
>
>
> --
> Thomas Broyer
> /tɔ.ma.bʁwa.je/ <http://xn--nna.ma.xn--bwa-xxb.je/> <
> http://xn--nna.ma.xn--bwa-xxb.je/>
>
Reply | Threaded
Open this post in threaded view
|

Re: Preferred way to execute Maven goals/phases from Maven plugins

Thomas Broyer-2
I'm not familiar with Maven Invoker, but the Maven Invoker Plugin does not
have such code.
It will call setMavenHome only if there's a configured value:
https://github.com/apache/maven-invoker-plugin/blob/dfd3c3680f31cb36ef1c14c18f4ea8b8d6115151/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java#L2104-L2109
See also
https://maven.apache.org/shared/maven-invoker/usage.html#Configuring_the_Maven_Home_Directory:
“You can use the method Invoker.setMavenHome() to specify which Maven
executable it should use. If you don't provide an explicit value for this
setting, the Invoker will automatically try to detect a Maven installation
by evaluating the system property maven.home and the environment variable
M2_HOME.”

On Mon, Nov 2, 2020 at 1:00 PM Nick Stolwijk <[hidden email]>
wrote:

> Thanks,
>
> I looked at the Maven Release Plugin and I see that the logic of where
> Maven is installed is not in the Maven-Invoker, but in the release plugin
> [1]. There is some logic on how to 'find' Maven, using environment
> variables like 'maven.home', 'MAVEN_HOME' and 'M2_HOME'. Does this mean
> that the choice of which setting is used and in which order is still the
> responsibility of the calling plugin? Or is there some standard for that?
>
> [1]
>
> https://github.com/apache/maven-release/blob/dbdf3a4a8cb8db51fa73963912555be4f39a89b8/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java#L318
>
> With regards,
>
> Nick Stolwijk
>
> ~~~ Try to leave this world a little better than you found it and, when
> your turn comes to die, you can die happy in feeling that at any rate you
> have not wasted your time but have done your best ~~~
>
> Lord Baden-Powell
>
>
> On Mon, Nov 2, 2020 at 12:27 PM Thomas Broyer <[hidden email]> wrote:
>
> > Maybe have a look at Maven Invoker:
> > https://maven.apache.org/shared/maven-invoker/
> > (it's what the Maven Invoker Plugin and Maven Release Plugin use)
> >
> > On Mon, Nov 2, 2020 at 11:28 AM Nick Stolwijk <[hidden email]>
> > wrote:
> >
> > > Hi folks,
> > >
> > > We are struggling with our buildserver (Jenkins) and the Git-Flow Maven
> > > Plugin[1] with regards to execute the Maven executable to run specific
> > > goals and phases during release (i.e. run versions plugin to change
> > version
> > > or run `mvn verify` to check project).
> > >
> > > The gitflow-m-p uses a flag to set the executable which needs to know
> if
> > it
> > > is on Linux (run mvn) or Windows (run mvn.cmd).
> > >
> > > I was wondering what is the 'right' way to execute Maven from a plugin.
> > > I've taken a look at the Maven Release Plugin and that one uses an
> > internal
> > > Executor framework. I have thought about Toolchain, but I didn't find
> an
> > > example of a toolchain with Maven itself.
> > >
> > > Can anyone enlighten me?
> > >
> > > [1] https://github.com/aleksandr-m/gitflow-maven-plugin
> > >
> > > With regards,
> > >
> > > Nick Stolwijk
> > >
> > > ~~~ Try to leave this world a little better than you found it and, when
> > > your turn comes to die, you can die happy in feeling that at any rate
> you
> > > have not wasted your time but have done your best ~~~
> > >
> > > Lord Baden-Powell
> > >
> >
> >
> > --
> > Thomas Broyer
> > /tɔ.ma.bʁwa.je/ <http://xn--nna.ma.xn--bwa-xxb.je/> <
> http://xn--nna.ma.xn--bwa-xxb.je/> <
> > http://xn--nna.ma.xn--bwa-xxb.je/>
> >
>


--
Thomas Broyer
/tɔ.ma.bʁwa.je/ <http://xn--nna.ma.xn--bwa-xxb.je/>
Reply | Threaded
Open this post in threaded view
|

Re: Preferred way to execute Maven goals/phases from Maven plugins

Karl Heinz Marbaise-3
In reply to this post by Nick_S
Hi,

On 02.11.20 11:27, Nick Stolwijk wrote:
> Hi folks,
>
> We are struggling with our buildserver (Jenkins) and the Git-Flow Maven
> Plugin[1] with regards to execute the Maven executable to run specific
> goals and phases during release (i.e. run versions plugin to change version
> or run `mvn verify` to check project).

In Jenkins you should run simple things like:

mvn clean verify

or if you deploy your artifacts to a repository manager:

mvn clean deploy

And check if your Jenkins uses the correct settings.xml (can be handled
via config-file-provider plugin in Jenkins).

If you like to make a release in Jenkins use a freestyle job to execute
that... via `mvn release:prepare release:perform`

I doubt that it would be a good idea to use git-flow-maven-plugin to
create a release ... Apart from that I think that git-flow is to complex
cause usually you don't need git flow with the complex branching model...

Kind regards
Karl Heinz Marbaise

>
> The gitflow-m-p uses a flag to set the executable which needs to know if it
> is on Linux (run mvn) or Windows (run mvn.cmd).
>
> I was wondering what is the 'right' way to execute Maven from a plugin.
> I've taken a look at the Maven Release Plugin and that one uses an internal
> Executor framework. I have thought about Toolchain, but I didn't find an
> example of a toolchain with Maven itself.
>
> Can anyone enlighten me?
>
> [1] https://github.com/aleksandr-m/gitflow-maven-plugin
>
> With regards,
>
> Nick Stolwijk
>
> ~~~ Try to leave this world a little better than you found it and, when
> your turn comes to die, you can die happy in feeling that at any rate you
> have not wasted your time but have done your best ~~~
>
> Lord Baden-Powell
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Preferred way to execute Maven goals/phases from Maven plugins

Nick_S
Hi Karl,

Unfortunately, the Maven-Release-Plugin doesn't cut it for us.

1. It doesn't support Tycho builds with regard to versions [1]
2. We do use release branches on our products (Eclipse RCP and docker
containers) to do some acceptance testing.

That's why we used to use the Atlassian Gitflow plugin (alas, they didn't
support Tycho either) and are now migrating to the aforementioned plugin.

[1]
https://www.eclipse.org/tycho/sitedocs/tycho-release/tycho-versions-plugin/set-version-mojo.html

With regards,

Nick Stolwijk

~~~ Try to leave this world a little better than you found it and, when
your turn comes to die, you can die happy in feeling that at any rate you
have not wasted your time but have done your best ~~~

Lord Baden-Powell


On Mon, Nov 2, 2020 at 2:00 PM Karl Heinz Marbaise <[hidden email]>
wrote:

> Hi,
>
> On 02.11.20 11:27, Nick Stolwijk wrote:
> > Hi folks,
> >
> > We are struggling with our buildserver (Jenkins) and the Git-Flow Maven
> > Plugin[1] with regards to execute the Maven executable to run specific
> > goals and phases during release (i.e. run versions plugin to change
> version
> > or run `mvn verify` to check project).
>
> In Jenkins you should run simple things like:
>
> mvn clean verify
>
> or if you deploy your artifacts to a repository manager:
>
> mvn clean deploy
>
> And check if your Jenkins uses the correct settings.xml (can be handled
> via config-file-provider plugin in Jenkins).
>
> If you like to make a release in Jenkins use a freestyle job to execute
> that... via `mvn release:prepare release:perform`
>
> I doubt that it would be a good idea to use git-flow-maven-plugin to
> create a release ... Apart from that I think that git-flow is to complex
> cause usually you don't need git flow with the complex branching model...
>
> Kind regards
> Karl Heinz Marbaise
>
> >
> > The gitflow-m-p uses a flag to set the executable which needs to know if
> it
> > is on Linux (run mvn) or Windows (run mvn.cmd).
> >
> > I was wondering what is the 'right' way to execute Maven from a plugin.
> > I've taken a look at the Maven Release Plugin and that one uses an
> internal
> > Executor framework. I have thought about Toolchain, but I didn't find an
> > example of a toolchain with Maven itself.
> >
> > Can anyone enlighten me?
> >
> > [1] https://github.com/aleksandr-m/gitflow-maven-plugin
> >
> > With regards,
> >
> > Nick Stolwijk
> >
> > ~~~ Try to leave this world a little better than you found it and, when
> > your turn comes to die, you can die happy in feeling that at any rate you
> > have not wasted your time but have done your best ~~~
> >
> > Lord Baden-Powell
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Preferred way to execute Maven goals/phases from Maven plugins

Karl Heinz Marbaise-3
Hi,

the Maven Release Plugin 3.0.0-M1... supports of writing own rules #1 ..
etc.

Furthermore  I would use simply things like versions-maven-plugin
otherwise (or tycho versions plugin to support OSGi with some script
steps in Jenkins for git magic (which I used a long time ago)...

What is the problem with release branches? ...

Kind regards
Karl Heinz Marbaise

#1:
https://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html#releaseStrategyId

On 02.11.20 14:07, Nick Stolwijk wrote:

> Hi Karl,
>
> Unfortunately, the Maven-Release-Plugin doesn't cut it for us.
>
> 1. It doesn't support Tycho builds with regard to versions [1]
> 2. We do use release branches on our products (Eclipse RCP and docker
> containers) to do some acceptance testing.
>
> That's why we used to use the Atlassian Gitflow plugin (alas, they didn't
> support Tycho either) and are now migrating to the aforementioned plugin.
>
> [1]
> https://www.eclipse.org/tycho/sitedocs/tycho-release/tycho-versions-plugin/set-version-mojo.html
>
> With regards,
>
> Nick Stolwijk
>
> ~~~ Try to leave this world a little better than you found it and, when
> your turn comes to die, you can die happy in feeling that at any rate you
> have not wasted your time but have done your best ~~~
>
> Lord Baden-Powell
>
>
> On Mon, Nov 2, 2020 at 2:00 PM Karl Heinz Marbaise <[hidden email]>
> wrote:
>
>> Hi,
>>
>> On 02.11.20 11:27, Nick Stolwijk wrote:
>>> Hi folks,
>>>
>>> We are struggling with our buildserver (Jenkins) and the Git-Flow Maven
>>> Plugin[1] with regards to execute the Maven executable to run specific
>>> goals and phases during release (i.e. run versions plugin to change
>> version
>>> or run `mvn verify` to check project).
>>
>> In Jenkins you should run simple things like:
>>
>> mvn clean verify
>>
>> or if you deploy your artifacts to a repository manager:
>>
>> mvn clean deploy
>>
>> And check if your Jenkins uses the correct settings.xml (can be handled
>> via config-file-provider plugin in Jenkins).
>>
>> If you like to make a release in Jenkins use a freestyle job to execute
>> that... via `mvn release:prepare release:perform`
>>
>> I doubt that it would be a good idea to use git-flow-maven-plugin to
>> create a release ... Apart from that I think that git-flow is to complex
>> cause usually you don't need git flow with the complex branching model...
>>
>> Kind regards
>> Karl Heinz Marbaise
>>
>>>
>>> The gitflow-m-p uses a flag to set the executable which needs to know if
>> it
>>> is on Linux (run mvn) or Windows (run mvn.cmd).
>>>
>>> I was wondering what is the 'right' way to execute Maven from a plugin.
>>> I've taken a look at the Maven Release Plugin and that one uses an
>> internal
>>> Executor framework. I have thought about Toolchain, but I didn't find an
>>> example of a toolchain with Maven itself.
>>>
>>> Can anyone enlighten me?
>>>
>>> [1] https://github.com/aleksandr-m/gitflow-maven-plugin
>>>
>>> With regards,
>>>
>>> Nick Stolwijk
>>>
>>> ~~~ Try to leave this world a little better than you found it and, when
>>> your turn comes to die, you can die happy in feeling that at any rate you
>>> have not wasted your time but have done your best ~~~
>>>
>>> Lord Baden-Powell
>>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]