Converting an Ant task definition to Gradle


(mark.harris) #1

I’m a Gradle n00b. I have been asked to convert an ages-old Ant build script to utilise Gradle instead.

My first task is related to an Ant task which creates a i18n properties file as part of the build. The task creates a new task definition which subsequently gets called by the build process (as it’s one of the tasks that the build target depends upon). It looks like this:

<target name="prepare-i18n" depends="ivy-retrieve" >
        <ivy:cachepath organisation="i18nlog" module="i18nlog" revision="1.0.9" inline="true" conf="default" pathid="i18nlog-classpath"/>
        <taskdef name="i18n" classpathref="i18nlog-classpath" classname="mazz.i18n.ant.I18NAntTask" />
</target>

mazz.i18n.ant.I18NAntTask is part of a jar included in the project’s classpath called “i18nlog-1.0.9”.

I cannot just import the Ant build file into my Gradle script as there are lots of task name clashes (e.g. “test”, “compile”) so I need to rewrite this task from scratch. I think I can include the jar within the Gradle task’s classpath, but I cannot find any information showing how to call the class contained therein. Is it possible?

Thanks.


(Luke Daley) #2

There’s a section in the userguide on using custom ant tasks.