Which language should I use in build.gradle? Ant, Groovy, Java?

I just started to learn Gradle and found gradle supports a lot of languages in build.gralde script: it can integrate with Ant build.xml and invoke the Ant task in build.gradle; it supports Groovy syntax and pure Java syntax…
For a single project’s build.gradle script, should I choose only one syntax to keep the build script neat?
I have the knowledge for Java, but not Groovy or Ant. Is it a good idea to use pure Java in build script? Or it’s better to learn about Groovy to take its advantage?

Begin using the declarative elements of Gradle (which are in fact Groovy code). Refrain from using explicit code - only if necessary.

1 Like

Hi @GentleMint,

In fact, Gradle supports writing build scripts in just one language, and that is Groovy*. It is possible to use Ant directly from within a Gradle build script, but this is done via Gradle’s AntBuilder API; you are not “writing the build script in a different language” when you do so. Nor does Gradle support writing build scripts in Java. You may have thought that this is the case because Groovy syntax is based on Java. Groovy’s syntax goes far beyond what Java can do, but most legal Java programs are also legal Groovy programs.

If you haven’t done so already, you’ll want to familiarize yourself with the Gradle User Guide and Gradle Build Language Reference.

*Note that Gradle has begun to support Kotlin as a second official language for writing build scripts, but this support is still in a very early stage. If you’re just getting to know Gradle, we recommend you get familiar with Gradle’s Groovy DSL.

1 Like

Thank you all very much. I am starting to get familiar with Groovy now.