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

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.xml:


<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
            xmlns:e="http://ant.apache.org/ivy/extra">
...
   <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" />
   </dependency>


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

Ant:


<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" />
</target>


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).

Tags: tool


Copyright © 2024 Jakub Holý
Powered by Cryogen
Theme by KingMob