How to get maven dependency sources and unpack them into the specified directory?

While I combine maven and vim, I cannot find a way to download all the sources that depend on my project and unpack them together.

So, I can generate tags easily.

Does anyone know how?

+4
source share
1 answer

You can use the maven-eclipse-plugin plugin to download sources and give you a list of available sources (some of them your dependencies may not have available sources).

A dependency plugin can also load sources, but it’s more difficult for you to get a list of the jars you need.

You can try something like this:

 dir=target/sources mkdir -p $dir mvn eclipse:eclipse -DdownloadSources sed -rn '/sourcepath/{s/.*sourcepath="M2_REPO.([^"]*).*/\1/;p}' .classpath | \ (cd $dir && xargs -i jar xf ~/.m2/repository/{}) 

This starts mvn eclipse:eclipse -DdownloadSources , which will load the sources and write the .classpath file to the local directory. This file contains the paths to your source banks. It looks something like this:

 <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src/main/java" including="**/*.java"/> <classpathentry kind="output" path="target/classes"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="var" path="M2_REPO/net/sourceforge/findbugs/jsr305/1.3.7/jsr305-1.3.7.jar"/> <classpathentry kind="var" path="M2_REPO/net/jcip/jcip-annotations/1.0/jcip-annotations-1.0.jar" sourcepath="M2_REPO/net/jcip/jcip-annotations/1.0/jcip-annotations-1.0-sources.jar"/> </classpath> 

In my example, you can see that there are sources for JCIP jar annotations, but not the FindBugs JSR305 gang.

The sed command retrieves the source jar paths (relative to your local maven repository). The xargs command then unpacks each source tank in $dir .

The eclipse plugin creates .classpath and .project files and the .project directory - you can delete them if you never use Eclipse.

+5
source

All Articles