Gradle-i-fying the ant tag

I’m trying to migrate an ant script to gradle - most of it is no problem, but I’ve run across this one thing I cannot seem to fix.

In our old build.xml we had:

<script language="javascript" src="someJs.js">
            someMethod("arg1", "arg2");

I try map this as:

task myTask {
  script(language:"javascript", src:"someJs.js") {
   "someMethod('arg1', 'arg2')"

However, it seems like someMethod is never run during compilation. How do I fix it so it does?

  1. You seem to be missing a semicolon at the end of your script. 2. The ant script task expects either a src attribute, or a script body, not both. 3. You might find groovy’s slashy strings or multiline strings are handy in this situation (

Also, it’s very important to wrap Ant calls in ‘doLast {}’. Otherwise they will get execution at configuration time, rather than execution time.

If the ant script task expects either a src or a body, there is no way to straight-up move from the old ant tag to gradle’s version, I guess?

Anyway, I decided fighting the grammar was too much work - I just include the script as before, and inside the script the last thing that happens is that I run the method. The params are luckily constants anyway.


Gradle calls the ant task so whatever the ant task can do, gradle can do.

I was referring to the ant task documentation here

src - The location of the script as a file, if not inline