The Holy Java

Building the right thing, building it right, fast

Ivy: Retrieve Both .jar And -sources.jar Into A Folder – Note to Self

Posted by Jakub Holý on July 25, 2011

After some experimenting I’ve found out how to tell Ivy (2.2.0) to retrieve also .jar with source codes into a folder:


<ivy-module version="2.0" xmlns:xsi="" xsi:noNamespaceSchemaLocation=""
   <dependency org="net.jakubholy.testing" name="dbunit-embeddedderby-parenttest" rev="1.2.0" conf="test" >
	<artifact name="dbunit-embeddedderby-parenttest" type="jar" />
	<artifact name="dbunit-embeddedderby-parenttest" type="sources" e:classifier="sources"  ext="jar" />
	<exclude org="junit" />

The important thing here is the second artifact line with type and classifier sources and extension jar.


<target name="ivy" description="Retrieve dependencies managed by Ivy into lib/">
	<ivy:settings file="ivysettings.xml" />
	<!-- Notice that with sync=true Ivy will also remove the files which do not need to be there -->
	<ivy:retrieve pattern="lib/[conf]/[artifact].[ext]" sync="true" type="jar" />
	<ivy:retrieve pattern="lib/[conf]/[artifact]-sources.[ext]" sync="false" type="sources" />

Notice the second retrieve line – the type is set to sources and we’ve changed also the pattern not to overwrite the normal .jar and we’ve also disabled sync for otherwise the normal .jar would be removed (I’m sure there must be a better way, perhaps combining the two into one line with type=”jar,sources” and a pattern which takes the type into account).

Sorry, the comment form is closed at this time.

%d bloggers like this: