Gilad
Gilad

Reputation: 618

Definning Ant task from Ivy dependency

I'm using IvyDE to manage my project dependencies and Ant to build my project and perform some other tasks.

So my ivy.xml file looks like this:

<ivy-module version="2.0">
<info organisation="test" module="test" revision="0-RELEASE"/>
<dependencies>
    <dependency org="com.generator" name="Generator" rev="2.0-RELEASE" />
</dependencies>
</ivy-module>

I want to define a new task in my build.xml file, something like this:

<taskdef name="generate" classname="com.Generator" />

Where the class com.Generator is packed in the ivy dependency.

Now the taskdef declaration would not compiled, this is because I did not set the classpath for the class.

My question is, if it is possible to refer to the ivy dependency from the build.xml file so I can define the new task ?

Thank you Gilad

Upvotes: 0

Views: 203

Answers (1)

Arne Burmeister
Arne Burmeister

Reputation: 20614

Yes you can:

The best way is to add an own configuration and its dependency for the task in your ivy.xml file:

<configuration>
  <conf name="generator" visibility="private"/>
</configuration>

<dependencies>
  …
  <dependency org="com.generator" 
      name="Generator" rev="2.0-RELEASE" 
      conf="generator->default"/>
</dependencies>

Then you can use it in your build.xml:

<ivy:cachepath pathid="generator.classpath" 
    conf="generator" log="quiet"/>
<taskdef name="generate" 
    classname="com.Generator" 
    classpathref="generator.classpath"/>

You need the ivy task defined to do so!

Upvotes: 2

Related Questions