Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven dependency plugin copy jar with dependencies

I'm trying to copy a jar from my local repository into another project as described here:

http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html

However my jar is coming out of maven-assembly-plugin as a "jar with dependencies", which puts the regular jar and the assembled jar in my local repo. The jar name looks something like:

example-test-0.0.1-SNAPSHOT-jar-with-dependencies.jar

and I can find it in the repo and use it if I copy manually. I thought it would be a good idea to let maven copy it so I used the dependency copy goal described above.

However I cant make it work so it copies the "jar with dependencies" jar.

This is how the pom looks like:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.10</version>
    <executions>
      <execution>
        <id>copy</id>
        <phase>package</phase>
        <goals>
          <goal>copy</goal>
        </goals>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>my.group</groupId>
              <artifactId>example-test</artifactId>
              <version>0.0.1-SNAPSHOT</version>
              <type>jar</type>
              <overWrite>true</overWrite>
              <outputDirectory>libs</outputDirectory>
              <destFileName>somename.jar</destFileName>
            </artifactItem>
          </artifactItems>

          <overWriteReleases>false</overWriteReleases>
          <overWriteSnapshots>true</overWriteSnapshots>
        </configuration>
      </execution>
    </executions>
  </plugin>

I tried to set the type to "jar-with-dependencies" but that didnt work. It only worked if I let the type as "jar" but then it copies the regular not assembled jar. Any ideas how to fix this?

like image 428
breakline Avatar asked Mar 10 '15 22:03

breakline


People also ask

What is copy dependency plugin in Maven?

org.apache.maven.plugins:maven-dependency-plugin:3.2.0:copy-dependencies Goal that copies the project dependencies from the repository to a defined location. Requires a Maven project to be executed. Requires dependency resolution of artifacts in scope: test.

What is the difference between Maven resources and dependencies?

maven-resources-plugin: The Resources Plugin handles the copying of project resources to the output directory. The main resources are the resources associated to the main source code. maven-dependency-plugin: The dependency plugin provides the capability to manipulate artifacts.

What is copy-dependencies goal in Maven?

org.apache.maven.plugins:maven-dependency-plugin:3.2.0:copy-dependencies Goal that copies the project dependencies from the repository to a defined location. Requires a Maven project to be executed.

What is Maven-dependency-plugin?

maven-dependency-plugin: The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified location. maven-jar-plugin: This plugin provides the capability to build and sign jars. Here is a complete pom.xml file.


1 Answers

If you have an artifact like this:

example-test-0.0.1-SNAPSHOT-jar-with-dependencies.jar

You want to reference it like this:

        <artifactItem>
          <groupId>my.group</groupId>
          <artifactId>example-test</artifactId>
          <version>0.0.1-SNAPSHOT</version>
          <type>jar</type>
          <classifier>jar-with-dependencies</classifier>
          <overWrite>true</overWrite>
          <outputDirectory>libs</outputDirectory>
          <destFileName>somename.jar</destFileName>
        </artifactItem>

The example is here:

        <artifactItem>
          <groupId>[ groupId ]</groupId>
          <artifactId>[ artifactId ]</artifactId>
          <version>[ version ]</version>
          <type>[ packaging ]</type>
  this---><classifier> [classifier - optional] </classifier>
          <overWrite>[ true or false ]</overWrite>
          <outputDirectory>[ output directory ]</outputDirectory>
          <destFileName>[ filename ]</destFileName>
        </artifactItem>
like image 110
EJC Avatar answered Oct 17 '22 13:10

EJC