2

I'm trying to copy all the dependencies of a project and its sub-modules to a specific folder (lets say parent/target/lib)

the project is something like this:

parent
|- module1
|- module2    
|- module3
   |- module3.1
   |- module3.2
|- module4

in my understanding the only way to do so is by using maven copy-dependency in each sub-module as so:

<execution>
    <id>copy-dependencies</id>
    <phase>package</phase>
    <goals>
        <goal>copy-dependencies</goal>
    </goals>
    <configuration>
        <includeScope>runtime</includeScope>
        <outputDirectory>${parent.dir}/target/lib</outputDirectory>
        <overWriteReleases>false</overWriteReleases>
        <overWriteSnapshots>false</overWriteSnapshots>
        <overWriteIfNewer>true</overWriteIfNewer>
        <excludeGroupIds>xerces</excludeGroupIds>
        <excludeArtifactIds>junit,testng,easymock</excludeArtifactIds>
    </configuration>
</execution>

I'm having multiple issues with this however:

  1. the lib folder will contain all versions of an artifact (i want only latest)
  2. for each include/exclude rule all the poms need to be updated (there are a lot)

Isn't there something that works together with dependency:list to get all dependencies, keep the latest and copy them to my /lib folder?

phury
  • 2,123
  • 2
  • 21
  • 33
  • Which errors do you get when running it? – Ale Sequeira Jul 16 '14 at 16:05
  • Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.4:copy-dependencies (copy-dependencies) on project module3: Error copying artifact from C:\Users\release\.m2\repository\net\jcip\jcip-annotations\1.0\jcip-annotations-1.0.jar to C:\dev\parent\target\lib\jcip-annotations-1.0.jar: Failed to copy full contents from C:\Users\release\.m2\repository\net\jcip\jcip-annotations\1.0\jcip-annotations-1.0.jar to C:\parent\target\lib\jcip-annotations-1.0.jar I get this for multiple dependencies, randomly. This is for issue #1 – phury Jul 16 '14 at 16:50
  • That's strange, did you try adding -X -e to see more details? – Ale Sequeira Jul 16 '14 at 18:06
  • its probably a corrupt jar or the file is locked.... the problem is that it happen randomly each time i run. I'm looking for other solution to do what i'm doing – phury Jul 16 '14 at 18:33

1 Answers1

1

I ended up using the assembly plugin in a new sub-project as follows:

parent
|- module1
|- module2    
|- module3
   |- module3.1
   |- module3.2
|- module4
|- assembly-module

The assembly-module calls the maven-assembly-plugin (pom.xml):

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <descriptor>src/assembly/bin.xml</descriptor>
                <finalName>module-assembly</finalName>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

finally my assembly file looks like this (assembly-module/src/assembly/bin.xml)

<id>bin</id>
<formats>
    <format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>

<dependencySets>
    <dependencySet>
        <outputDirectory>lib</outputDirectory>
        <scope>runtime</scope>
        <useProjectArtifact>false</useProjectArtifact>
        <includes/>
        <excludes>
            <exclude>org.eclipse.jdt:core</exclude>
        </excludes>
    </dependencySet>
</dependencySets>
phury
  • 2,123
  • 2
  • 21
  • 33