Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use maven dependency:copy goal?

I have 2 artifacts that I'd like to copy from my local repository to a directory in filesystem.

I think dependency:copy does this job. But, it requires an argument artifactItems. http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html

Can any one help me with using this goal in command line. Unfortunately, maven doesnt show the usage of this goal in command line.

like image 508
user691197 Avatar asked Jun 26 '12 10:06

user691197


2 Answers

Rather than trying to figure out how to provide an artifactItem by command line, I'd configure the command line execution for the dependency plugin. Do that by specifying default-cli as the execution ID. If you always want to copy the same dependencies, you could hardcode the GAV coords in the artifact item(s). Or, hardcode any values that remain constant between commands.

To copy different artifacts via command line, use properties as element values and specify the values on the command line. For example, if configuration for artifactItem included <artifactId>${copy.artifactId}</artifactId> then

mvn dependency:copy -Dcopy.artifactId=myArtifact

would copy myArtifact (example assumes other elements have hardcoded values).

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.4</version>
    <executions>
    <execution>
    <id>default-cli</id> 
    <configuration>
      <artifactItems>
        <artifactItem>
          <!-- hardcode values, or use properties, depending on what you want to do -->
          <groupId>[ groupId ]</groupId>
          <artifactId>[ artifactId ]</artifactId>
          <version>[ version ]</version>
          <type>[ packaging ]</type>
          <outputDirectory>/the/filesystem/dir</outputDirectory>
        </artifactItem>
      </artifactItems>
      <!-- other configurations here -->
    </configuration>
    </execution>
    </executions>
  </plugin>
like image 172
user944849 Avatar answered Oct 21 '22 14:10

user944849


Not sure if you want to do this from within a Maven project or without one. In case of the former, you can use this:

mvn dependency:copy -Dartifact='group.id:artifact.id:your.version'

In case you define the version of the artifact in your pom.xml using properties, you can also have it use that version like this:

mvn dependency:copy -Dartifact='group.id:artifact.id:${version.property}'
like image 33
robinst Avatar answered Oct 21 '22 12:10

robinst