" Last question: the diff between project.getDependencies() and project.getDependencyArtifacts() is basically that getDependencies() returns also transitive dependencies?"
Yes. Although see my previous message under "dependencyResolution question" because I noticed that test scope things where included in getDependencyArtifacts. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Saturday, January 07, 2006 11:42 PM To: Maven Users List Subject: RE: [m2] How to get artifact and Maven project for dependencies and transitive dependencies Indeed this fixes it and I start to see something going ... Thanks a lot! Last question: the diff between project.getDependencies() and project.getDependencyArtifacts() is basically that getDependencies() returns also transitive dependencies? I'm assuming it follows the guidelines as documented at http://maven.apache.org/guides/introduction/introduction-to-dependency-m echanism.html. Chris "Brian E. Fox" <[EMAIL PROTECTED]> wrote: You'd think as the author of the dependEncy plugin, I would know how to spell dependEncy. Change the resolution line to have an e instead of an a: * @requiresDependencyResolution compile I tested this quickly and once that is corrected, it listed all my dependEncies. ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Saturday, January 07, 2006 11:28 PM To: Brian E. Fox Subject: RE: [m2] How to get artifact and Maven project for dependencies and transitive dependencies Nope, doesn't help. Let me show you a TestMojo I just created: /** * Test Mojo * * @goal test * @requiresDependancyResolution compile */ public class TestMojo extends AbstractMojo { /** * The Maven Project. * * @parameter expression="${project}" * @required * @readonly */ private MavenProject project = null; /** * Execute Mojo. * * @throws MojoExecutionException If an error occurs. * @throws MojoFailureException If an error occurs. */ public void execute() throws MojoExecutionException, MojoFailureException { // get logger Log logger = getLog(); Set artifacts = project.getArtifacts(); if (artifacts == null) { logger.error("No artifacts"); } else { logger.info("Starting to iterate through artifacts"); for (Iterator i = artifacts.iterator(); i.hasNext();) { Artifact a = (Artifact) i.next(); logger.info("Artifact: " + a.getId()); } } logger.info("Done"); artifacts = project.getDependencyArtifacts(); if (artifacts == null) { logger.error("No artifacts"); } else { logger.info("Starting to iterate through artifacts"); for (Iterator i = artifacts.iterator(); i.hasNext();) { Artifact a = (Artifact) i.next(); logger.info("Artifact: " + a.getId()); } } logger.info("Done"); } } The example dependencies in the POM are configured like: log4j log4j 1.2.13 dom4j dom4j 1.6 compile junit junit 3.8.1 test commons-dbcp commons-dbcp 1.2 And all I get is: [INFO] [mhave:test] [INFO] Starting to iterate through artifacts [INFO] Done [ERROR] No artifacts [INFO] Done [INFO] ------------------------------------------------------------------------ - --- [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ - "Brian E. Fox" wrote: This is probably because you need to have @requiresDependancyResolution compile|test set in your mojo. The xxx-dependencies in the plugin I mentioned have this set. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Saturday, January 07, 2006 10:51 PM To: Maven Users List Subject: RE: [m2] How to get artifact and Maven project for dependencies and transitive dependencies Brian, Thanks for the pointer. I will take a look at the code of the plugin. However, just a fyi: project.getArtifacts() returns an empty list for me (even that I have dependencies defined, and I get them listed with my own plugin and with "mvn site"). The same with project.getDependencyArtifacts() (and I don't exactly understand what this should do anyways) except that it returns "null". Thanks, Chris "Brian E. Fox" wrote: Take a look at the http://mojo.codehaus.org/dependency-maven-plugin all the code in there is about resolving dependencies and walking through various dependency lists to filter type,scope, etc. I imagine all the code you need will be in there. Basically you just need to call project.getArtifacts and that will be all transitive included. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Saturday, January 07, 2006 9:59 PM To: Maven Users List Subject: Re: [m2] How to get artifact and Maven project for dependencies and transitive dependencies Thanks for the point Allan. However, I need to clarify that I'm not trying to resolve the dependencies within my plugin. My plugin does create a dependency report similar to project-info-reports:dependencies, however with the output as XML file, so that it can be rendered into various formats (e.g. XHTML, Plain text, PDF, etc.). I basically looked up the code in the plugin maven-project-info-reports-plugin, but it contains a lot of "TODOs". That's why I'm not sure if there is a better way to do the dependency resolution. Thanks, Chris Allan Ramirez wrote: Please try this link http://docs.codehaus.org/display/MAVENUSER/FAQs#FAQs-HowdoIgetaplugin%27 sdependenciesfromaMojo%3F -allan [EMAIL PROTECTED] wrote: >Hi, > >As part of my effort to write a customized dependency report (in XML), I looked at the maven-project-reports-info-plugin to understand how the dependency resolution works. I made a slight modification, as it somehow didn't produce the results I wanted. I'm doing the following: > >To get a list of dependencies for a Maven project (List object contains a list of Dependency objects): > > // get list of dependencies > List dependencies = project.getDependencies(); > > >To get the project artifact associated with a dependency: > > // create project artifact for dependency > Artifact depArtifact = > artifactFactory > .createProjectArtifact(dependency.getGroupId(), dependency > .getArtifactId(), dependency.getVersion(), > dependency.getScope()); > > >To get a Maven project object associated with an artifact (assuming that the Artifact type is "pom"): > > // get project associated with artifact > return mavenProjectBuilder.buildFromRepository(artifact, > project.getRemoteArtifactRepositories(), localRepository); > > >At last I'm resolving transitive dependencies by looking up the Maven project object associated with a dependency, getting a list of dependencies from that project object, getting the project artifact associated with each of those dependencies (to get download URL and description). I can parse the dependency tree by doing this recursively (though I'm stopping at level 1 at this point). > >Can anybody tell me if there is a better way (and possibly a way which guarantees that this still will work with Maven 2.1+) to do this work? > >Thanks, >Chris > > > > >----------------------------------------------------------------------- >- > >No virus found in this incoming message. >Checked by AVG Free Edition. >Version: 7.1.371 / Virus Database: 267.14.14/222 - Release Date: >1/5/2006 > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]