3

There are very few documentations and examples on this (those exists are useless).

I would like to copy all the dependencies of a given pom.xml file. Usually, I can use mvn dependency:copy-dependencies on command line or use maven-dependecy-plugin configuration in the pom file.

However, I would like to do it programmatically on a given pom.xml file. So far, I figured that I will need to use MavenCli

MavenCli cli = new MavenCli();
cli.doMain(new String[]{"clean", "dependency:copy-dependencies", "-DincludeScope=runtime"}, "C:\\workspace\\gui", null, null);

where "C:\\workspace\\gui" is a directory containing a pom.xml

but the above code gives me the following error:

 [ERROR] Failed to execute goal on project test-pom: Could not resolve dependencies for project gigadot:test-pom:jar:0.5-SNAPSHOT: Failed to collect dependencies for [commons-lang:commons-lang:jar:2.6 (compile), commons-io:commons-io:jar:2.0.1 (compile), org.apache.commons:commons-exec:jar:1.1 (compile), org.apache.commons:commons-math:jar:2.2 (compile), xom:xom:jar:1.2.5 (compile), log4j:log4j:jar:1.2.16 (provided)]: Failed to read artifact descriptor for org.apache.commons:commons-math:jar:2.2: Could not transfer artifact org.apache.commons:commons-math:pom:2.2 from/to central (http://repo1.maven.org/maven2): No connector available to access repository central (http://repo1.maven.org/maven2) of type default using the available factories -> [Help 1]

Does anyone know how to solve this problem?

gigadot
  • 8,879
  • 7
  • 35
  • 51
  • Perhaps http://stackoverflow.com/questions/2910162/how-to-get-an-artifact-download-url-via-maven-api can gives some pointers? – Raghuram Nov 21 '11 at 05:02
  • Given that the pom is just an xml file, you could just use a dom library (like dom4j) and an xpath expression to grab all dependencies - just out of interest, why do you need to do this? – Romski Aug 09 '12 at 13:18
  • @Romski doing what you said will not include the transitive dependencies. The reason I wanted to do this is because I was building dynamic plugable system. I would like the dependencies of the jar plugin to be included in the classpath automatically. – gigadot Aug 10 '12 at 03:04
  • In doxia there exists macros - could you use this? http://maven.apache.org/doxia/macros/index.html#Snippet_Macro Or writing you an owned maven plugin mojo? If so, maybe there is a api to get the dependency information via maven project Class? – Huluvu424242 Aug 24 '12 at 20:56

1 Answers1

0

Add this dependency to MavenCLI project

<dependencies>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-embedder</artifactId>
        <version>3.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.eclipse.aether</groupId>
        <artifactId>aether-connector-wagon</artifactId>
        <version>0.9.0.M2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-http-lightweight</artifactId>
        <version>2.5</version>
    </dependency>
</dependencies>
MariuszS
  • 30,646
  • 12
  • 114
  • 155