4
votes

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 currently have build.gradle which contains only this:

ant.importBuild 'build.xml'

I can build the project using Ant like this:

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

However, when I build with Gradle, Ant complains it cannot find the properties set in build.properties. I've tried setting the Ant property, but it doesn't seem to get picked up:

ant.properties['user.properties.file'] = '/home/me/.netbeans/6.5/build.properties'

I've also tried setting a system property:

systemProperties 'user.properties.file': '/home/me/.netbeans/6.5/build.properties'

but this doesn't work either. Ideally I'd like to set this property in ~/.gradle/gradle.properties as just about all of our projects need it.

How can I set this property in Gradle and have Ant pick it up when called from Gradle?

1
Have you tried to place ant.properties before ant.importBuild?Peter Niederwieser
Thanks!...that worked in the project's build.gradle file. However, I have the property set in ~/.gradle/gradle.properties and in the top-level build.gradle file. Why aren't these being picked up? I need this property set in almost all of the projects, so I'd like to set it once, especially since this is user-specific.user2180144
I don't quite understand what you are saying, but ant.properties is per project. Of course you can do something like allprojects { ant.properties[...] = ... }.Peter Niederwieser
If ant.properties is per-project, that may explain why it isn't working. What I'm saying is I have a repository with multiple projects in it, all of which are Ant projects. Just about all of them require the Ant user.properties.file property to be set. I would like to set this Ant property in one place, say in the gradle.properties file or in the build.gradle file at the top of the repo. If I take the approach of adding ant.properties before the ant.importBuild, I'll have to add the property to all build.gradle files. (cont'd.)...user2180144
As I said, you can do allprojects { ... } in the top-level build.gradle file. properties.gradle isn't suitable because it sets Gradle (project) properties, not Ant properties. You should also think about a way to avoid the need for every developer to customize the build script(s). For example, you can get the (OS) username with System.getProperty("user.name").Peter Niederwieser

1 Answers

0
votes

If you want to set load the properties on multiple Gradle projects you could use a Gradle init script, http://www.gradle.org/docs/current/userguide/init_scripts.html. Inside the init script you would put this code:

allProjects {
    ant.properties['user.properties.file'] = '/home/me/.netbeans/6.5/build.properties'
}