How to enforce running my Maven Plugin with a certain Java version

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

How to enforce running my Maven Plugin with a certain Java version

Konrad Windszus
How can I enforce that my custom Maven Plugin (or only a certain Mojo within) is only executed with at least a certain Java version (i.e. Java8 due to the use of class files being only compatible with Java8+). The prerequisites section which seems like the natural way to define that only allows me to require a minimum Maven version (http://maven.apache.org/ref/3.5.0/maven-model/maven.html#class_prerequisites). which is not what I want here.

The failure message is rather unintuitive whenever my Maven Mojo is used in a project with an incompatible Java version (which cannot read my Mojos class files).

I know that in all Projects using the Maven Plugin the maven-enforcer-plugin could theoretically be used, but then each consuming projects needs to manually figure out the minimum java version based on the documentation of all Maven Plugins. Isn't there a better/more automated way, which let's Maven check this requirement prior to executing any Mojos from a plugin?

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

Reply | Threaded
Open this post in threaded view
|

Re: How to enforce running my Maven Plugin with a certain Java version

rfscholte
Hi,

AFAIK there's no solution for it out of the box.
The pom model has no option to specify it, so it cannot be solved there.
The plugin descriptor is a Maven-only file, so that might work, but  
requires Maven to understand it.
The other possible solution it to write an extension for it, which would  
also work with older versions of Maven.

This is also one of the main reasons why we still use Java7 to develop, so  
users won't hit this issue.

Robert

On Thu, 28 Sep 2017 12:46:33 +0200, Konrad Windszus <[hidden email]>  
wrote:

> How can I enforce that my custom Maven Plugin (or only a certain Mojo  
> within) is only executed with at least a certain Java version (i.e.  
> Java8 due to the use of class files being only compatible with Java8+).  
> The prerequisites section which seems like the natural way to define  
> that only allows me to require a minimum Maven version  
> (http://maven.apache.org/ref/3.5.0/maven-model/maven.html#class_prerequisites).  
> which is not what I want here.
>
> The failure message is rather unintuitive whenever my Maven Mojo is used  
> in a project with an incompatible Java version (which cannot read my  
> Mojos class files).
>
> I know that in all Projects using the Maven Plugin the  
> maven-enforcer-plugin could theoretically be used, but then each  
> consuming projects needs to manually figure out the minimum java version  
> based on the documentation of all Maven Plugins. Isn't there a  
> better/more automated way, which let's Maven check this requirement  
> prior to executing any Mojos from a plugin?
>
> Thanks,
> Konrad
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]

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

Reply | Threaded
Open this post in threaded view
|

Re: How to enforce running my Maven Plugin with a certain Java version

Hervé BOUTEMY
I fully agree with the analysis

thinking at it, it seems we could provide a backward compatible option:
instead of changing pom.xml model to add more prerequisite features [1], why
don't we enhance META-INF/maven/plugin.xml [2] ?

Notice that, as I write that, I see that even maven version prerequisite would
better be in META-INF/maven/plugin.xml than in pom.xml...

WDYT?

Regards,

Hervé

[1] http://maven.apache.org/ref/3.5.0/maven-model/
maven.html#class_prerequisites

[2] http://maven.apache.org/ref/3.5.0/maven-plugin-api/plugin.html

Le jeudi 28 septembre 2017, 22:22:02 CEST Robert Scholte a écrit :

> Hi,
>
> AFAIK there's no solution for it out of the box.
> The pom model has no option to specify it, so it cannot be solved there.
> The plugin descriptor is a Maven-only file, so that might work, but
> requires Maven to understand it.
> The other possible solution it to write an extension for it, which would
> also work with older versions of Maven.
>
> This is also one of the main reasons why we still use Java7 to develop, so
> users won't hit this issue.
>
> Robert
>
> On Thu, 28 Sep 2017 12:46:33 +0200, Konrad Windszus <[hidden email]>
>
> wrote:
> > How can I enforce that my custom Maven Plugin (or only a certain Mojo
> > within) is only executed with at least a certain Java version (i.e.
> > Java8 due to the use of class files being only compatible with Java8+).
> > The prerequisites section which seems like the natural way to define
> > that only allows me to require a minimum Maven version
> > (http://maven.apache.org/ref/3.5.0/maven-model/maven.html#class_prerequisi
> > tes). which is not what I want here.
> >
> > The failure message is rather unintuitive whenever my Maven Mojo is used
> > in a project with an incompatible Java version (which cannot read my
> > Mojos class files).
> >
> > I know that in all Projects using the Maven Plugin the
> > maven-enforcer-plugin could theoretically be used, but then each
> > consuming projects needs to manually figure out the minimum java version
> > based on the documentation of all Maven Plugins. Isn't there a
> > better/more automated way, which let's Maven check this requirement
> > prior to executing any Mojos from a plugin?
> >
> > Thanks,
> > Konrad
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]



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