0

I try to figure out how to copy all dependencies to an explicit version and all the required dependencies.

For Example: My project requires version 3 of a third party lib, called foobar. I want to copy the version 3 libraries to a folder named lib-foobar-${foobar.version}.
In this folder are those jars which are required to use foobar in version 3. That means the jar itself and all dependent jars which are declared in the foobar pom.

I currently use the org.codehaus.mojo:maven-dependency-plugin:2.1 with goal copy-dependencies in phase package.
My configuration is:

<configuration>
    <outputDirectory>${project.build.directory}/lib-foobar-${foobar.version}</outputDirectory>
    <includeGroupIds>com.foobar</includeGroupIds>
    <excludeTransitive>false</excludeTransitive>
    <excludeScope>test</excludeScope>
    <includeScope>compile</includeScope>
</configuration>

I don't want to list all allowed and not allowed lib's because a step to a newer version takes place every month.

Are there any other tools which can do that or is there any dodge for that?

Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
javaBeCool
  • 276
  • 3
  • 13

1 Answers1

3

Big thanks to user944849.

It was very helpful to me for finding out the best solution in that case.

For everyone who is interested in my solution, here it comes:

At first I changed the plugin to maven-assemby-plugin and added a new assembly file

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <dependencies>
           <dependency>
            <groupId>com.foobar</groupId>
            <artifactId>foobar-parent</artifactId>
            <version>${foobar.version}</version>
            <type>pom</type>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>copy-foobar</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
             <configuration>
                <descriptors>
                  <descriptor>src/assemble/foobar-libs.xml</descriptor>
                </descriptors>
            </configuration>
           </execution> 
         </executions>
      </plugin>

And the assembly file looks like:

<assembly
  xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  <id>standalone</id>
  <formats>
    <format>dir</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <includes>
        <include>org.foobar</include>
      </includes>
      <outputDirectory>/lib-foobar-${foobar.version}</outputDirectory>
      <useProjectArtifact>true</useProjectArtifact>
      <useTransitiveFiltering>true</useTransitiveFiltering>
      <unpack>false</unpack>
    </dependencySet>
  </dependencySets>

</assembly>

The key was the <useTransitiveFiltering> element, which resolves all transitive libs based on the included libs.

steamer25
  • 9,278
  • 1
  • 33
  • 38
javaBeCool
  • 276
  • 3
  • 13