Reputation: 4073
Some open source license require to distribute the original code for each dependency. I need to make the extracted sources available to my maven assembly plugin.
How to recursively get all the source-JARs for every single dependency used?
dependency:sources
does only download source-dependencies to the local Maven repo, and not to a custom directory that I need to define.
Upvotes: 1
Views: 971
Reputation: 4073
Solution found:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>get-dependency-sources</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${sources.directory}</outputDirectory>
<classifier>sources</classifier>
<prependGroupId>true</prependGroupId>
</configuration>
</execution>
</executions>
</plugin>
in combination with
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>unpack-sources</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<move todir="${sources.directory}">
<fileset dir="${sources.directory}">
<include name="**/*.jar"/>
</fileset>
<mapper type="glob" from="*.jar" to="*.zip"/>
</move>
</target>
</configuration>
</execution>
...
First collects all resources within ${sources.directory}
and then renames the jars to zip files (which enables a "normal" user to view their contents in Windows Explorer.
Alternatively you can also directly unzip the jars using the unzip
ANT task.
Upvotes: 2