You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Guillaume Duchesneau <gd...@taleo.com> on 2007/02/28 21:18:29 UTC

How to inject dependencies from a mojo

Hello,

 

I would like to inject some dependencies from inside a mojo execution so
that other plugins in the lifecycle can see those new dependencies as if
they had been declared in the POM. 

 

I naively tried something like this (see below) but other plugins in the
lifecycle do not "see" the dependencies I inject (my plugin is bound to
the validate phase).  Does anyone know how to achieve this?

 

/**

 * MyMojo

 * 

 * @goal inject-dependencies

 */

public class MyMojo extends AbstractMojo

{

    /**

     * The project whose project files to create.

     * 

     * @parameter expression="${project}"

     * @required

     * @readonly

     */

    protected MavenProject project;

 

    public void execute()

    {

        List dependencies = project.getDependencies();

 

        Dependency dep = new Dependency();

        dep.setGroupId("commons-collections");

        dep.setArtifactId("commons-collections");

        dep.setVersion("1.0");

 

        dependencies.add(dep);

    }

}

 

Thanks in advance...

 

Guillaume

 


Re: How to inject dependencies from a mojo

Posted by Eric Redmond <er...@gmail.com>.
Dependencies are already resolved before the lifecycle even starts... why do
you want to do this?

Eric

On 2/28/07, Guillaume Duchesneau <gd...@taleo.com> wrote:
>
> Hello,
>
>
>
> I would like to inject some dependencies from inside a mojo execution so
> that other plugins in the lifecycle can see those new dependencies as if
> they had been declared in the POM.
>
>
>
> I naively tried something like this (see below) but other plugins in the
> lifecycle do not "see" the dependencies I inject (my plugin is bound to
> the validate phase).  Does anyone know how to achieve this?
>
>
>
> /**
>
> * MyMojo
>
> *
>
> * @goal inject-dependencies
>
> */
>
> public class MyMojo extends AbstractMojo
>
> {
>
>     /**
>
>      * The project whose project files to create.
>
>      *
>
>      * @parameter expression="${project}"
>
>      * @required
>
>      * @readonly
>
>      */
>
>     protected MavenProject project;
>
>
>
>     public void execute()
>
>     {
>
>         List dependencies = project.getDependencies();
>
>
>
>         Dependency dep = new Dependency();
>
>         dep.setGroupId("commons-collections");
>
>         dep.setArtifactId("commons-collections");
>
>         dep.setVersion("1.0");
>
>
>
>         dependencies.add(dep);
>
>     }
>
> }
>
>
>
> Thanks in advance...
>
>
>
> Guillaume
>
>
>
>


-- 
Eric Redmond
http://codehaus.org/~eredmond