You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Sascha Vogt <sa...@gmail.com> on 2012/09/27 14:36:24 UTC

How to find out if a dependency is a Maven plugin?

Hi all,

I currently have a small issue with upgrading to Maven 3 and a custom
mojo I wrote.

I need to find out if the dependency is a Maven plugin. With Maven 2.x
one could check the type by comparing Artifact.getType() to
"maven-plugin". With Maven 3 this returns now "jar" instead of
"maven-plugin".
Is there any other way to find out if a dependency is a Maven plugin?
Any pointers to the API would be greatly appreciated!

E.g. up to Maven 3 this code did work:

MavenProject prj = ...
for(Iterator i = prj.getDependencyArtifacts().iterator(); i.hasNext();)
{
   Artifact artifact = (Artifact) i.next();
   if( "maven-plugin".equals( artifact.getType() ) ) {
      //do some specific stuff
   }
}

Greetings
-Sascha-

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Chris Graham <ch...@gmail.com>.
:-) hey, no stress. I'd rather find out sooner rather than later.

What I had wanted to do was to make use of some code (not via a mojo; just treat it as a normal jar dependency; just like we would any other jar dep) that is contained in another plugin (both controlled by me).

So do I have to release the common code as a third component (ie jar in it's own right)?

-Chris

Sent from my iPhone

On 28/09/2012, at 5:43 PM, Sascha Vogt <sa...@gmail.com> wrote:

> Hey Chris,
> 
> I'm sorry :( This was not my intention.
> 
> See the other mail, we found a workaround ;)
> 
> Greetings
> -Sascha-
> 
> Am 28.09.2012 07:50, schrieb Chris Graham:
>> Yes, thanks. You've send me back to the drawing board...
>> 
>> On 28/09/2012, at 12:23 AM, Sascha Vogt <sa...@gmail.com> wrote:
>> 
>>> First of all, thank you very much for the explanation. I wasn't aware of
>>> that up to know. Will definitely look into a different solution.
>>> Nevertheless I want to understand a bit more to evaluate possible ways
>>> to go.
>>> 
>>> Am 27.09.2012 16:06, schrieb Jörg Schaible:
>>>>> Am 27.09.2012 15:07, schrieb Jörg Schaible:
>>>>>> Sascha Vogt wrote:
>>>>> The idea was to have one Mojo extend another Mojo.
>>>> In M2, it is simply not reliable and should therefore never be done.
>>> Ok, for M2 the stuff we did is bad :) For now let's concentrate on M3
>>> 
>>>>> There is also a
>>>>> maven-inherit-plugin out there
>>>>> (https://github.com/ops4j/org.ops4j.pax.construct/tree/master/maven-
>>>> inherit-plugin)
>>>>> which suffers from the same issue.
>>>> 
>>>> Yes, I complained about that before.
>>>> 
>>>>> What do you mean by different classloader model?
>>>> 
>>>> M3 uses isolated classloaders for the individual plugins.
>>> So with the isolated classloaders the extension of a plugin could/should
>>> work as expected (aka even if there are multiple different versions
>>> referenced)? Or do you mean that in M3 if I extend plugin a, my plugin
>>> shouldn't see classes from plugin a?
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Sascha Vogt <sa...@gmail.com>.
Hey Chris,

I'm sorry :( This was not my intention.

See the other mail, we found a workaround ;)

Greetings
-Sascha-

Am 28.09.2012 07:50, schrieb Chris Graham:
> Yes, thanks. You've send me back to the drawing board...
> 
> On 28/09/2012, at 12:23 AM, Sascha Vogt <sa...@gmail.com> wrote:
> 
>> First of all, thank you very much for the explanation. I wasn't aware of
>> that up to know. Will definitely look into a different solution.
>> Nevertheless I want to understand a bit more to evaluate possible ways
>> to go.
>>
>> Am 27.09.2012 16:06, schrieb Jörg Schaible:
>>>> Am 27.09.2012 15:07, schrieb Jörg Schaible:
>>>>> Sascha Vogt wrote:
>>>> The idea was to have one Mojo extend another Mojo.
>>> In M2, it is simply not reliable and should therefore never be done.
>> Ok, for M2 the stuff we did is bad :) For now let's concentrate on M3
>>
>>>> There is also a
>>>> maven-inherit-plugin out there
>>>> (https://github.com/ops4j/org.ops4j.pax.construct/tree/master/maven-
>>> inherit-plugin)
>>>> which suffers from the same issue.
>>>
>>> Yes, I complained about that before.
>>>
>>>> What do you mean by different classloader model?
>>>
>>> M3 uses isolated classloaders for the individual plugins.
>> So with the isolated classloaders the extension of a plugin could/should
>> work as expected (aka even if there are multiple different versions
>> referenced)? Or do you mean that in M3 if I extend plugin a, my plugin
>> shouldn't see classes from plugin a?


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Chris Graham <ch...@gmail.com>.
Yes, thanks. You've send me back to the drawing board...

-Chris

Sent from my iPhone

On 28/09/2012, at 12:23 AM, Sascha Vogt <sa...@gmail.com> wrote:

> First of all, thank you very much for the explanation. I wasn't aware of
> that up to know. Will definitely look into a different solution.
> Nevertheless I want to understand a bit more to evaluate possible ways
> to go.
> 
> Am 27.09.2012 16:06, schrieb Jörg Schaible:
>>> Am 27.09.2012 15:07, schrieb Jörg Schaible:
>>>> Sascha Vogt wrote:
>>> The idea was to have one Mojo extend another Mojo.
>> In M2, it is simply not reliable and should therefore never be done.
> Ok, for M2 the stuff we did is bad :) For now let's concentrate on M3
> 
>>> There is also a
>>> maven-inherit-plugin out there
>>> (https://github.com/ops4j/org.ops4j.pax.construct/tree/master/maven-
>> inherit-plugin)
>>> which suffers from the same issue.
>> 
>> Yes, I complained about that before.
>> 
>>> What do you mean by different classloader model?
>> 
>> M3 uses isolated classloaders for the individual plugins.
> So with the isolated classloaders the extension of a plugin could/should
> work as expected (aka even if there are multiple different versions
> referenced)? Or do you mean that in M3 if I extend plugin a, my plugin
> shouldn't see classes from plugin a?
> 
> Greetings
> -Sascha-
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Hervé BOUTEMY <he...@free.fr>.
the documentation is here http://maven.apache.org/plugin-tools/maven-plugin-
plugin/examples/using-annotations.html

and a lot of plugins now use these annotations: 
http://jira.codehaus.org/browse/MPLUGIN-203

Regards,

Hervé

Le vendredi 28 septembre 2012 11:43:30 Sascha Vogt a écrit :
> Am 28.09.2012 10:41, schrieb Jörg Schaible:
> > You're aware that modern Maven plugins use now real annotations
> > themselves?
> 
> I've heard of it, but the last time I searched for it (a few months ago)
> did not yet find any documentation or even core plugins using that
> mechanism to see how it looks like or how I'm supposed to use them. Do
> you happen to have any pointers to start with?
> 
> And as I said, in that particular case we try to extend the
> maven-jaxb2-plugin we have to live with what we get anyways ;)
> 
> Greetings
> -Sascha-
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Sascha Vogt <sa...@gmail.com>.
Am 28.09.2012 10:41, schrieb Jörg Schaible:
> You're aware that modern Maven plugins use now real annotations themselves?
I've heard of it, but the last time I searched for it (a few months ago)
did not yet find any documentation or even core plugins using that
mechanism to see how it looks like or how I'm supposed to use them. Do
you happen to have any pointers to start with?

And as I said, in that particular case we try to extend the
maven-jaxb2-plugin we have to live with what we get anyways ;)

Greetings
-Sascha-

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Jörg Schaible <Jo...@scalaris.com>.
Hi Sascha,

Sascha Vogt wrote:

> Hi,
> 
> Am 27.09.2012 18:42, schrieb Jörg Schaible:
>> In M3 the plugins are no longer shared within the reactor i.e. each
>> plugin is using its own classloader and can therefore have any arbitrary
>> dependency. So if your plugin depends on another plugin, there should be
>> no difference to any other dependency. However, I never tried this in M3
>> and I have therefore no idea how the plugin-plugin will actually react
>> when you build yours.
> So this still leaves the question, how does one find out the real "type"
> of a dependency (aka is this dependency a maven-plugin).
> 
> Regarding the real problem we found a simpler solution. We intended to
> extend the maven-jaxb2-plugin and found that they themself use Mojo
> inheritance across different plugins. They do so, by not using xdoclet
> annotations for the parameters but real annotations and the
> maven-plugin-tools-anno [0]

You're aware that modern Maven plugins use now real annotations themselves?

> 
> With the same approach we were able to extend our Mojos as well, so for
> M3 this seems to be a workable solutions.
> 
> For M2, we might have to think about it - but probably (as this is only
> used in a very controlled environment) we can live with the restriction
> to only ever reference one version of any given plugin, thus eliminating
> the risk of incompatible versions being referenced in different places.

Actually we found out about this problem the hard way, because we used the 
xdoclet-plugin that depends on an ancient antrun-plugin ...

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Sascha Vogt <sa...@gmail.com>.
Hi,

Am 27.09.2012 18:42, schrieb Jörg Schaible:
> In M3 the plugins are no longer shared within the reactor i.e. each plugin 
> is using its own classloader and can therefore have any arbitrary 
> dependency. So if your plugin depends on another plugin, there should be no 
> difference to any other dependency. However, I never tried this in M3 and I 
> have therefore no idea how the plugin-plugin will actually react when you 
> build yours.
So this still leaves the question, how does one find out the real "type"
of a dependency (aka is this dependency a maven-plugin).

Regarding the real problem we found a simpler solution. We intended to
extend the maven-jaxb2-plugin and found that they themself use Mojo
inheritance across different plugins. They do so, by not using xdoclet
annotations for the parameters but real annotations and the
maven-plugin-tools-anno [0]

With the same approach we were able to extend our Mojos as well, so for
M3 this seems to be a workable solutions.

For M2, we might have to think about it - but probably (as this is only
used in a very controlled environment) we can live with the restriction
to only ever reference one version of any given plugin, thus eliminating
the risk of incompatible versions being referenced in different places.

Thx all for the help and clarifications!
Greetings
-Sascha-

[0]http://wiki.jfrog.org/confluence/display/OSS/Maven+Anno+Mojo

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Jörg Schaible <jo...@gmx.de>.
Sascha Vogt wrote:

> First of all, thank you very much for the explanation. I wasn't aware of
> that up to know. Will definitely look into a different solution.
> Nevertheless I want to understand a bit more to evaluate possible ways
> to go.
> 
> Am 27.09.2012 16:06, schrieb Jörg Schaible:
>>> Am 27.09.2012 15:07, schrieb Jörg Schaible:
>>>> Sascha Vogt wrote:
>>> The idea was to have one Mojo extend another Mojo.
>> In M2, it is simply not reliable and should therefore never be done.
> Ok, for M2 the stuff we did is bad :) For now let's concentrate on M3
> 
>>> There is also a
>>> maven-inherit-plugin out there
>>> (https://github.com/ops4j/org.ops4j.pax.construct/tree/master/maven-
>> inherit-plugin)
>>> which suffers from the same issue.
>> 
>> Yes, I complained about that before.
>> 
>>> What do you mean by different classloader model?
>> 
>> M3 uses isolated classloaders for the individual plugins.
> So with the isolated classloaders the extension of a plugin could/should
> work as expected (aka even if there are multiple different versions
> referenced)? Or do you mean that in M3 if I extend plugin a, my plugin
> shouldn't see classes from plugin a?

In M3 the plugins are no longer shared within the reactor i.e. each plugin 
is using its own classloader and can therefore have any arbitrary 
dependency. So if your plugin depends on another plugin, there should be no 
difference to any other dependency. However, I never tried this in M3 and I 
have therefore no idea how the plugin-plugin will actually react when you 
build yours.

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Sascha Vogt <sa...@gmail.com>.
First of all, thank you very much for the explanation. I wasn't aware of
that up to know. Will definitely look into a different solution.
Nevertheless I want to understand a bit more to evaluate possible ways
to go.

Am 27.09.2012 16:06, schrieb Jörg Schaible:
>> Am 27.09.2012 15:07, schrieb Jörg Schaible:
>>> Sascha Vogt wrote:
>> The idea was to have one Mojo extend another Mojo.
> In M2, it is simply not reliable and should therefore never be done.
Ok, for M2 the stuff we did is bad :) For now let's concentrate on M3

>> There is also a
>> maven-inherit-plugin out there
>> (https://github.com/ops4j/org.ops4j.pax.construct/tree/master/maven-
> inherit-plugin)
>> which suffers from the same issue.
> 
> Yes, I complained about that before.
> 
>> What do you mean by different classloader model?
> 
> M3 uses isolated classloaders for the individual plugins.
So with the isolated classloaders the extension of a plugin could/should
work as expected (aka even if there are multiple different versions
referenced)? Or do you mean that in M3 if I extend plugin a, my plugin
shouldn't see classes from plugin a?

Greetings
-Sascha-

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Jörg Schaible <Jo...@scalaris.com>.
Sascha Vogt wrote:

> Am 27.09.2012 15:07, schrieb Jörg Schaible:
>> Sascha Vogt wrote:
>>> I need to find out if the dependency is a Maven plugin. With Maven 2.x
>>> one could check the type by comparing Artifact.getType() to
>>> "maven-plugin". With Maven 3 this returns now "jar" instead of
>>> "maven-plugin".
>>> Is there any other way to find out if a dependency is a Maven plugin?
>>> Any pointers to the API would be greatly appreciated!
>>> [snip]
>> 
>> Why do you want to know? In M2 a plugin should never be a dependency of
>> another one anyway, because you will face all kind of unexpected effects
>> due to the different classloader model.
> The idea was to have one Mojo extend another Mojo.

In M2, it is simply not reliable and should therefore never be done.

> There is also a
> maven-inherit-plugin out there
> (https://github.com/ops4j/org.ops4j.pax.construct/tree/master/maven-
inherit-plugin)
> which suffers from the same issue.

Yes, I complained about that before.

> What do you mean by different classloader model?

M3 uses isolated classloaders for the individual plugins.

M2 will load every plugin once and only once. If you plugin depends on 
plugin x in version 2.x, but it is used elsewhere in the reactor in version 
1.x, it depends on the build sequence, which version is actually used - 
point is that your plugin has absolutely no control over version of the 
depending plugin - never. The inherit-plugin is therefore the best candidate 
to break every big multi-project build in subtle ways. You have been warned!

- Jörg



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Sascha Vogt <sa...@gmail.com>.
Am 27.09.2012 15:07, schrieb Jörg Schaible:
> Sascha Vogt wrote:
>> I need to find out if the dependency is a Maven plugin. With Maven 2.x
>> one could check the type by comparing Artifact.getType() to
>> "maven-plugin". With Maven 3 this returns now "jar" instead of
>> "maven-plugin".
>> Is there any other way to find out if a dependency is a Maven plugin?
>> Any pointers to the API would be greatly appreciated!
>> [snip]
> 
> Why do you want to know? In M2 a plugin should never be a dependency of 
> another one anyway, because you will face all kind of unexpected effects due 
> to the different classloader model.
The idea was to have one Mojo extend another Mojo. There is also a
maven-inherit-plugin out there
(https://github.com/ops4j/org.ops4j.pax.construct/tree/master/maven-inherit-plugin)
which suffers from the same issue.

What do you mean by different classloader model?

Greetings
-Sascha-

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Jörg Schaible <Jo...@scalaris.com>.
Chris Graham wrote:

> Really?
> 
> A plugin can not/should not use another plugin as a dep?
> 
> So how is the archiver used? Extended?

The archiver is not a plugin, it is a component that is used by a lot of 
plugins.

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Chris Graham <ch...@gmail.com>.
Really?

A plugin can not/should not use another plugin as a dep?

So how is the archiver used? Extended?

-Chris, who is puzzled.

Sent from my iPhone

On 27/09/2012, at 11:07 PM, Jörg Schaible <Jo...@scalaris.com> wrote:

> Hi Sascha,
> 
> Sascha Vogt wrote:
> 
>> Hi all,
>> 
>> I currently have a small issue with upgrading to Maven 3 and a custom
>> mojo I wrote.
>> 
>> I need to find out if the dependency is a Maven plugin. With Maven 2.x
>> one could check the type by comparing Artifact.getType() to
>> "maven-plugin". With Maven 3 this returns now "jar" instead of
>> "maven-plugin".
>> Is there any other way to find out if a dependency is a Maven plugin?
>> Any pointers to the API would be greatly appreciated!
>> 
>> E.g. up to Maven 3 this code did work:
>> 
>> MavenProject prj = ...
>> for(Iterator i = prj.getDependencyArtifacts().iterator(); i.hasNext();)
>> {
>>   Artifact artifact = (Artifact) i.next();
>>   if( "maven-plugin".equals( artifact.getType() ) ) {
>>      //do some specific stuff
>>   }
>> }
> 
> Why do you want to know? In M2 a plugin should never be a dependency of 
> another one anyway, because you will face all kind of unexpected effects due 
> to the different classloader model.
> 
> - Jörg
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: How to find out if a dependency is a Maven plugin?

Posted by Jörg Schaible <Jo...@scalaris.com>.
Hi Sascha,

Sascha Vogt wrote:

> Hi all,
> 
> I currently have a small issue with upgrading to Maven 3 and a custom
> mojo I wrote.
> 
> I need to find out if the dependency is a Maven plugin. With Maven 2.x
> one could check the type by comparing Artifact.getType() to
> "maven-plugin". With Maven 3 this returns now "jar" instead of
> "maven-plugin".
> Is there any other way to find out if a dependency is a Maven plugin?
> Any pointers to the API would be greatly appreciated!
> 
> E.g. up to Maven 3 this code did work:
> 
> MavenProject prj = ...
> for(Iterator i = prj.getDependencyArtifacts().iterator(); i.hasNext();)
> {
>    Artifact artifact = (Artifact) i.next();
>    if( "maven-plugin".equals( artifact.getType() ) ) {
>       //do some specific stuff
>    }
> }

Why do you want to know? In M2 a plugin should never be a dependency of 
another one anyway, because you will face all kind of unexpected effects due 
to the different classloader model.

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org