You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Kai Hackemesser <ka...@gmail.com> on 2010/02/22 22:59:50 UTC

Re: Begginer's question: How can I use an other Mojo in my own plugin?

Hi, James,

that tip is almost good! But this one executes the mojo, and I want to have
the mojo object accessible, as I want to access a field. In more details, I
want to call the getResults() method on ResolveDependenciesMojo to get hold
of the dependencies.
The actual scenario: I want to build a classpath string containing some
dependencies of the plugin and the dependencies of the current project. Or I
need a list of resolved jar files for the same set of dependencies.

Cheers,
Kai

2010/2/22 James William Dumay <ja...@atlassian.com>

> Hey Kai,
> You might want to checkout the Mojo Executor project :)
>
> http://code.google.com/p/mojo-executor/
>
> James
>
>
> Kai Hackemesser wrote:
>
>> Hi,
>>
>> I would like to execute another Mojo (the ResolveDependenciesMojo) from
>> inside my own Mojo. I wasn't yet successful in adding it with the
>> @component
>> annotation. What is a proper way to do that?
>>
>> Cheers,
>> Kai
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Begginer's question: How can I use an other Mojo in my own plugin?

Posted by Kai Hackemesser <ka...@gmail.com>.
I found a way to get my plugin dependencies from outside:

    @SuppressWarnings("unchecked")
    List<Artifact> pluginArtifacts =
pluginManager.getPluginDescriptorForPrefix("myPrefix").getArtifacts();

    Artifact plugin = null;
    for(Artifact artifact: pluginArtifacts){
      if(artifact.getArtifactId().equals("theArtifactImLookingFor")){
        plugin  = artifact;
        break;
      }
    }

Cheers,
Kai

2010/2/23 Stephen Connolly <st...@gmail.com>

> ahh you want the dependencies of your plugin... as distinct from the
> dependencies of the project your plugin is running in... I can't remember
> exactly what you need to inject... somebody (Benjamin maybe) might have it
> on the tip of their tongue... otherwise you'll have to wait while I look it
> up
>
> Sent from my [rhymes with tryPod] ;-)
>
>
> On 23 Feb 2010, at 00:50, Kai Hackemesser <ka...@gmail.com>
> wrote:
>
>  Ok, I can try that. How can I get the dependencies of the current plugin?
>> I
>> tried to get them with
>> pluginManager.getPluginDefinitionForPrefix("myprefix", session,
>> project).getDependencies() but that returned only an empty list.
>>
>> Cheers,
>> Kai
>>
>> 2010/2/23 Stephen Connolly <st...@gmail.com>
>>
>>  depending on another maven plugin is a bad plan.  Due to issues with how
>>> Maven 2 loads plugins, the first version of a plugin loaded in a
>>> multi-module build is the only version that is loaded.
>>>
>>> Maven 3 will fix this somewhat, but in essence your build will be
>>> completely
>>> unpredictable if you try to depend on another plugin.
>>>
>>> IIRC getting the resolved dependencies is actually quite easy from within
>>> maven (just annotate the mojo with @requiresDependencyResolution scope
>>> where
>>> scope is the scope you require and then I think annotate a field with
>>> @parameter expression="${project.artifacts}" or something similar...
>>> you're
>>> making your life more complex by trying to depend on a separate plugin
>>>
>>> -Stephen
>>>
>>> On 22 February 2010 21:59, Kai Hackemesser <kai.hackemesser@gmail.com
>>>
>>>> wrote:
>>>>
>>>
>>>  Hi, James,
>>>>
>>>> that tip is almost good! But this one executes the mojo, and I want to
>>>>
>>> have
>>>
>>>> the mojo object accessible, as I want to access a field. In more
>>>> details,
>>>>
>>> I
>>>
>>>> want to call the getResults() method on ResolveDependenciesMojo to get
>>>>
>>> hold
>>>
>>>> of the dependencies.
>>>> The actual scenario: I want to build a classpath string containing some
>>>> dependencies of the plugin and the dependencies of the current project.
>>>>
>>> Or
>>>
>>>> I
>>>> need a list of resolved jar files for the same set of dependencies.
>>>>
>>>> Cheers,
>>>> Kai
>>>>
>>>
>>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Begginer's question: How can I use an other Mojo in my own plugin?

Posted by Stephen Connolly <st...@gmail.com>.
ahh you want the dependencies of your plugin... as distinct from the  
dependencies of the project your plugin is running in... I can't  
remember exactly what you need to inject... somebody (Benjamin maybe)  
might have it on the tip of their tongue... otherwise you'll have to  
wait while I look it up

Sent from my [rhymes with tryPod] ;-)

On 23 Feb 2010, at 00:50, Kai Hackemesser <ka...@gmail.com>  
wrote:

> Ok, I can try that. How can I get the dependencies of the current  
> plugin? I
> tried to get them with
> pluginManager.getPluginDefinitionForPrefix("myprefix", session,
> project).getDependencies() but that returned only an empty list.
>
> Cheers,
> Kai
>
> 2010/2/23 Stephen Connolly <st...@gmail.com>
>
>> depending on another maven plugin is a bad plan.  Due to issues  
>> with how
>> Maven 2 loads plugins, the first version of a plugin loaded in a
>> multi-module build is the only version that is loaded.
>>
>> Maven 3 will fix this somewhat, but in essence your build will be
>> completely
>> unpredictable if you try to depend on another plugin.
>>
>> IIRC getting the resolved dependencies is actually quite easy from  
>> within
>> maven (just annotate the mojo with @requiresDependencyResolution  
>> scope
>> where
>> scope is the scope you require and then I think annotate a field with
>> @parameter expression="${project.artifacts}" or something  
>> similar... you're
>> making your life more complex by trying to depend on a separate  
>> plugin
>>
>> -Stephen
>>
>> On 22 February 2010 21:59, Kai Hackemesser <kai.hackemesser@gmail.com
>>> wrote:
>>
>>> Hi, James,
>>>
>>> that tip is almost good! But this one executes the mojo, and I  
>>> want to
>> have
>>> the mojo object accessible, as I want to access a field. In more  
>>> details,
>> I
>>> want to call the getResults() method on ResolveDependenciesMojo to  
>>> get
>> hold
>>> of the dependencies.
>>> The actual scenario: I want to build a classpath string containing  
>>> some
>>> dependencies of the plugin and the dependencies of the current  
>>> project.
>> Or
>>> I
>>> need a list of resolved jar files for the same set of dependencies.
>>>
>>> Cheers,
>>> Kai
>>

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


Re: Begginer's question: How can I use an other Mojo in my own plugin?

Posted by Kai Hackemesser <ka...@gmail.com>.
Ok, I can try that. How can I get the dependencies of the current plugin? I
tried to get them with
pluginManager.getPluginDefinitionForPrefix("myprefix", session,
project).getDependencies() but that returned only an empty list.

Cheers,
Kai

2010/2/23 Stephen Connolly <st...@gmail.com>

> depending on another maven plugin is a bad plan.  Due to issues with how
> Maven 2 loads plugins, the first version of a plugin loaded in a
> multi-module build is the only version that is loaded.
>
> Maven 3 will fix this somewhat, but in essence your build will be
> completely
> unpredictable if you try to depend on another plugin.
>
> IIRC getting the resolved dependencies is actually quite easy from within
> maven (just annotate the mojo with @requiresDependencyResolution scope
> where
> scope is the scope you require and then I think annotate a field with
> @parameter expression="${project.artifacts}" or something similar... you're
> making your life more complex by trying to depend on a separate plugin
>
> -Stephen
>
> On 22 February 2010 21:59, Kai Hackemesser <kai.hackemesser@gmail.com
> >wrote:
>
> > Hi, James,
> >
> > that tip is almost good! But this one executes the mojo, and I want to
> have
> > the mojo object accessible, as I want to access a field. In more details,
> I
> > want to call the getResults() method on ResolveDependenciesMojo to get
> hold
> > of the dependencies.
> > The actual scenario: I want to build a classpath string containing some
> > dependencies of the plugin and the dependencies of the current project.
> Or
> > I
> > need a list of resolved jar files for the same set of dependencies.
> >
> > Cheers,
> > Kai
>

Re: Begginer's question: How can I use an other Mojo in my own plugin?

Posted by Stephen Connolly <st...@gmail.com>.
depending on another maven plugin is a bad plan.  Due to issues with how
Maven 2 loads plugins, the first version of a plugin loaded in a
multi-module build is the only version that is loaded.

Maven 3 will fix this somewhat, but in essence your build will be completely
unpredictable if you try to depend on another plugin.

IIRC getting the resolved dependencies is actually quite easy from within
maven (just annotate the mojo with @requiresDependencyResolution scope where
scope is the scope you require and then I think annotate a field with
@parameter expression="${project.artifacts}" or something similar... you're
making your life more complex by trying to depend on a separate plugin

-Stephen

On 22 February 2010 21:59, Kai Hackemesser <ka...@gmail.com>wrote:

> Hi, James,
>
> that tip is almost good! But this one executes the mojo, and I want to have
> the mojo object accessible, as I want to access a field. In more details, I
> want to call the getResults() method on ResolveDependenciesMojo to get hold
> of the dependencies.
> The actual scenario: I want to build a classpath string containing some
> dependencies of the plugin and the dependencies of the current project. Or
> I
> need a list of resolved jar files for the same set of dependencies.
>
> Cheers,
> Kai
>
> 2010/2/22 James William Dumay <ja...@atlassian.com>
>
> > Hey Kai,
> > You might want to checkout the Mojo Executor project :)
> >
> > http://code.google.com/p/mojo-executor/
> >
> > James
> >
> >
> > Kai Hackemesser wrote:
> >
> >> Hi,
> >>
> >> I would like to execute another Mojo (the ResolveDependenciesMojo) from
> >> inside my own Mojo. I wasn't yet successful in adding it with the
> >> @component
> >> annotation. What is a proper way to do that?
> >>
> >> Cheers,
> >> Kai
> >>
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>