mwcz
mwcz

Reputation: 9301

Is it possible to launch Gradle tasks from Ant?

I am researching replacements for Ant. I've looked at Gant and Gradle.

Is it possible to kick off a Gradle task from Ant? This is possible in Gant with a taskdef.

<taskdef
    name         = "gant"
    classname    = "org.codehaus.gant.ant.Gant"
    classpathref = "classpath" 
    />

<gant />

Is there something similar Gradle? I'm eager to start migrating from Ant to Gradle, but we have a large Ant infrastructure and any Gradle build scripts I create need to be callable from Ant.

Thanks!

Upvotes: 3

Views: 7319

Answers (4)

Jeremy Bunn
Jeremy Bunn

Reputation: 671

Create a macrodef for gradle, call it just like any other task. Here is the setup and an example...

    <!-- Gradle path stuff -->
<property environment="env" />
<condition property="gradle.executable" value="${env.GRADLE_HOME}/bin/gradle.bat" else="${env.GRADLE_HOME}/bin/gradle">
    <os family="windows" />
</condition>

<!-- Macro def, gives us an ant 'gradle' task-->
<macrodef name="gradle">
    <attribute name="task" />
    <sequential>
        <exec executable="${gradle.executable}" dir="." failonerror="true">
            <arg value="@{task}" />
        </exec>
    </sequential>
</macrodef>

Example of using the macro def

<!-- Example, call grade with new macro -->
<target name="example">
    <gradle task="build" />
</target>

Upvotes: 8

mig
mig

Reputation: 41

Actually I want to do the same thing and where implemented by calling a sh file and then the sh was calling the gradle but it was too much around the bush and finally the following code made it to work cool..

Hope this will help you..

<property environment="env" />
<property name="gradle.wrapper.executable" location="${env.GRADLE_HOME}/bin/gradle" />
<target name="dependencies-report" description="Creates a text file report of the depdency tree">
<exec executable="${gradle.wrapper.executable}" dir=".">
    <arg value="dependencyReport" />
</exec>
</target>

Upvotes: 3

Mark O&#39;Connor
Mark O&#39;Connor

Reputation: 77971

Instead of switching build technology, why not use a combination of ivy and groovy to extend the capabilities of your existing ant builds?

An example is the following posting:

Parse HTML using with an Ant Script

BTW I'm a big fan of Gradle, however, like you I have to live with and support a large ANT legacy :-)

Upvotes: 3

Peter Niederwieser
Peter Niederwieser

Reputation: 123910

Gradle doesn't offer an Ant task to run a Gradle build from Ant. What you could do is to invoke a Gradle command (like gradle build) from Ant.

In terms of Ant integration, Gradle offers two features: Importing Ant builds, and reusing Ant tasks.

Gradle is very different from Gant. Gradle is an entire new build system; Gant is a thin layer above Ant.

Upvotes: 1

Related Questions