1

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.

5
  • This is not possible. What if you depend on a proprietary library that whose code is not public? Commented Feb 26, 2016 at 9:14
  • Of course this would not work if the sources are not available via maven. But most of them are. As I stated in my post I am only talking about open source components. Commented Feb 26, 2016 at 9:16
  • By the way, dependency:sources resolves the sources for all dependencies of your project (including transitive ones). So Im not sure why you're saying it isn't recursive. Commented Feb 26, 2016 at 9:20
  • the goal you mentioned has a parameter "outputFile" - does that not do what you need it to do? see: maven.apache.org/plugins/maven-dependency-plugin/… Commented Feb 26, 2016 at 11:30
  • No it does not, OutputFile specifies some kind of logFILE not a directory. Commented Feb 26, 2016 at 12:35

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.