You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by 陈思淼 <ch...@gmail.com> on 2008/09/17 16:43:49 UTC

How to get all dependecy in a mojo ?

My mojo extends AbstractWarMojo, I want to get all the Project's
dependencies including the transitive denpendecies. So i config the
MavenProject in my mojo like thsi:
>
>  /**
>
     * The maven project.
>
     *
>
     * @parameter expression="${project}"
>
     * @required
>
     * @readonly
>
     */
>
    private MavenProject project;

project.getArtifacts() is a empty collection. I saw war plugin and them get
all the war's dependencies in this way? who can tell me how to get all
dependecy in a mojo ?
Thank you.

Re: How to get all dependecy in a mojo ?

Posted by lukewpatterson <lu...@gmail.com>.
Here is a snippet from something I'm currently working on.  It can see the
transitive dependencies with getArtifacts().


in the mojo:

 * @goal add-externalized-properties
 * @phase process-resources
 * @requiresDependencyResolution compile
 */
public class AddExternalizedPropertiesMojo extends AbstractMojo {
...
    /**
     * @parameter expression="${project}"
     * @required
     * @readonly
     */
    private MavenProject project;

------------------------------------------------------

in resulting META-INF\maven\plugin.xml:

<plugin>
  ...
  <mojos>
    <mojo>
      <goal>add-externalized-properties</goal>
      ...
      <requiresDependencyResolution>compile</requiresDependencyResolution>
      ...
      <phase>process-resources</phase>
-- 
View this message in context: http://www.nabble.com/How-to-get-all-dependecy-in-a-mojo---tp19533728p19544802.html
Sent from the Maven - Users mailing list archive at Nabble.com.


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


Re: How to get all dependecy in a mojo ?

Posted by 陈思淼 <ch...@gmail.com>.
I got the expect result.I use mvn compile myplugin:mojo to run my own task,
instead of mvn myplugin:mojo. It works.

Is it because the compile phase to load the dependency graph of the
project,  even if I use @requiresDependencyResolution test it doesn't work.



2008/9/17 Brian E. Fox <br...@reply.infinity.nu>

> You need to add @requiresDependencyResolution test (or compile etc)
>
> -----Original Message-----
> From: 陈思淼 [mailto:chensimiao@gmail.com]
> Sent: Wednesday, September 17, 2008 10:44 AM
> To: Maven Users List
> Subject: How to get all dependecy in a mojo ?
>
> My mojo extends AbstractWarMojo, I want to get all the Project's
> dependencies including the transitive denpendecies. So i config the
> MavenProject in my mojo like thsi:
> >
> >  /**
> >
>     * The maven project.
> >
>     *
> >
>     * @parameter expression="${project}"
> >
>     * @required
> >
>     * @readonly
> >
>     */
> >
>    private MavenProject project;
>
> project.getArtifacts() is a empty collection. I saw war plugin and them get
> all the war's dependencies in this way? who can tell me how to get all
> dependecy in a mojo ?
> Thank you.
>

RE: How to get all dependecy in a mojo ?

Posted by "Brian E. Fox" <br...@reply.infinity.nu>.
You need to add @requiresDependencyResolution test (or compile etc)

-----Original Message-----
From: 陈思淼 [mailto:chensimiao@gmail.com] 
Sent: Wednesday, September 17, 2008 10:44 AM
To: Maven Users List
Subject: How to get all dependecy in a mojo ?

My mojo extends AbstractWarMojo, I want to get all the Project's
dependencies including the transitive denpendecies. So i config the
MavenProject in my mojo like thsi:
>
>  /**
>
     * The maven project.
>
     *
>
     * @parameter expression="${project}"
>
     * @required
>
     * @readonly
>
     */
>
    private MavenProject project;

project.getArtifacts() is a empty collection. I saw war plugin and them get
all the war's dependencies in this way? who can tell me how to get all
dependecy in a mojo ?
Thank you.

Re: How to get all dependecy in a mojo ?

Posted by lukewpatterson <lu...@gmail.com>.
Is this what you are looking for?

    [1]
    /**
     * All dependencies that this project has, including transitive ones.
     * Contents are lazily populated, so depending on what phases have run
dependencies in some scopes won't be included.
     * eg. if only compile phase has run, dependencies with scope test won't
be included.
     *
     * @return {@link Set} &lt; {@link Artifact} >
     * @see #getDependencyArtifacts() to get only direct dependencies
     */
    public Set getArtifacts()
    {
        return artifacts == null ? Collections.EMPTY_SET : artifacts;
    }
    


Also keep in keep in mind effects of @requiresDependencyResolution [2]


[1] -
http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/MavenProject.java?view=markup
[2] - http://maven.apache.org/developers/mojo-api-specification.html

-- 
View this message in context: http://www.nabble.com/How-to-get-all-dependecy-in-a-mojo---tp19533728p19534612.html
Sent from the Maven - Users mailing list archive at Nabble.com.


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