Search code examples
mavenandroid-maven-plugin

Maven copy parents declared in the POMs


My final goal is to create a Maven repository in a certain directory containing only a certain set of artifacts and all their dependencies.

For this I use the following command:

mvn.bat dependency:copy-dependencies -f dependencies.pom
        -DoutputDirectory=localRepoDir -Dmdep.useRepositoryLayout=true
        -Dmdep.copyPom=true -Dmdep.addParentPoms=true

dependencies.pom being:

<project>
  <modelVersion>4.0.0</modelVersion>
  <description>Dependencies</description>
  <groupId>com.dummy</groupId>
  <artifactId>dummy</artifactId>
  <version>1.0.0</version>
  <dependencies>
    <dependency>
      <groupId>com.dependency1</groupId>
      <artifactId>dep1</artifactId>
      <version>1.0.0</version>
    </dependency>
    <dependency>
      <groupId>com.dependency2</groupId>
      <artifactId>dep2</artifactId>
      <version>1.0.0</version>
    </dependency>
  </dependencies>
</project>

When doing this, I notice that parents declared in the dependencies' poms are not copied from the .m2 Local maven repository to the destination directory.

Perhaps I'm missing something and there's a better way to do this, since it's kind of a hack to use a pom file to declare the artifacts I want to copy (together with their dependencies).


Solution

  • Turns out that maven was using version 2.8 as default for the dependency plugin. When explicitly indicating it to use the latest version (2.10), it worked just fine.

    The addParentPoms parameter was already introduced on 2.8 for copy-dependencies, so I guess it must be a bug in the 2.8 release.

    mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:copy-dependencies