user2180144
user2180144

Reputation: 91

Build NetBeans Ant Project from Gradle

I'm converting our build from Ant to Gradle. Our first step is to add the Gradle build files so we can start using Gradle as our build tool. This lets us use our existing build scripts to build using Ant and convert them to Gradle over time. I want to simply have Gradle call the existing Ant build files. Our projects are all NetBeans projects, which have build.xml and nbproject/build-impl.xml files. Some of the projects require NetBeans build properties, which can be found at ~/.netbeans/6.5.1/build.properties. I have the NetBeans user.properties.file property successfully set to ~/.netbeans/6.5.1/build.properties.

When I build with Ant, I invoke this:

ant -Duser.properties.file=~/.netbeans/6.5.1/build.properties dist

This executes the dist target, which depends on the init target which depends on the targets listed below:

pre-init, init-private, init-userdir, init-user, init-project, do-init, post-init, init-check, -init-taskdefs

The targets listed above are executed in the order specified. When I invoke 'gradle dist', it invokes the init Ant target, but then it executes the targets listed above in reverse order, starting with -init-taskdefs. There are required properties which are setup in the targets before the -init-taskdefs target which aren't being setup when run from gradle.

Really, all I want to do right now is to use gradle to invoke Ant to build my projects. What's the best way to do this since using gradle to build using Ant build.xml files doesn't seem to work as expected? Do I have to resort to using exec? (I hope not).

Upvotes: 2

Views: 741

Answers (1)

Stephen M -on strike-
Stephen M -on strike-

Reputation: 1077

I found trying to use Gradle's integration of Ant with a Netbeans project was too difficult and error prone. Instead, I use Gradle's exec() command. Below is an example, lifted from my code that builds a NetBeans Project named 'Common Library'.

task commonLibrary {
    doLast {
        ant.echo("Building Common Library")
        exec () {
            workingDir = "../netbeans/nb/CommonLibrary"
            executable = "ant"
            args = ['clean', 'jar']
        }
    }
}

I realize that wasn't the answer you were hoping for, but posted it as a possible solution for other people, particular people who aren't in a position to start reworking their build.xml files.

Upvotes: 0

Related Questions