In-depth documentation for more advanced Gradle-based Ant Targets?

(Christopher Rucinski) #1

Gradle has some documentation for Ant, but it doesn’t seem to tell us how we can map Ant targets to there Gradle equivalent. It does show how to map a small subset of Ant targets, but it doesn’t show how to do advanced usages of that subset. So am I missing this documentation, or does it not exist.

I have the code below of what I want to do. I think I need a chained mapper, but I don’t know how the DSL should look like.


I was having a slight inconvenience with my current Gradle Task. Either I can ignore the problem (just for now) or I can have 2 ant calls which will basically double the time to execute my Gradle task.

I have seen that using pure Ant, I can do this with just one Ant copy XML tag. I want to replicate that to reduce my execution time.

However, I cannot find the documentation to understand how to accurately map Ant targets to Gradle Ant tasks. So where can I find this documentation? I think I need a Chained Mapper

I have checked these documentation pages…



doLast {

    println("Syncing files...\n\tfrom\t'$intelliJColorSchemeDir' \n\tto\t\t'$sourceDir'")
    println("Renaming file extension")

    // Sync files from IntelliJ's color scheme and rename extension
    ant.copy(todir: sourceDir) {
        fileset(dir: intelliJColorSchemeDir)
        mapper(type: "glob", from: "*.icls", to: "*.xml")

        // Cannot do this as there will then be 2 mappers
        // mapper(type: "glob", from: "ChroMATERIAL IntelliJ IDEA*.*", to: "ChroMATERIAL*.*")    // TODO wildcards don't work in this case. Why? Should I just not use wildcards? Would kind of prefer wildcards though

    // ALTERNATIVE 2nd ant target - would like to have this be in the above ant `copy` target
    // Rename one specific file
    ant.move(todir: sourceDir) {
        fileset(dir: sourceDir)
        mapper(type: "glob", from: "ChroMATERIAL IntelliJ IDEA.xml", to: "ChroMATERIAL.xml")

    println("Syncing task completely finished!")


(Schalk Cronjé) #2

What is the motivation for using Ant for this case? I believe you can do all of that in a single Copy task or using one project.copy closure.

Example with just project.copy.

copy {
  into sourceDir
  from intelliJColorSchemeDir, {
    include '**'
    rename '(.+)\.icls', '$1.xml'
    rename 'ChroMATERIAL IntelliJ IDEA.xml','ChroMATERIAL.xml'

(Christopher Rucinski) #3

While you typed in the code correctly, the website changes the double \\ into a single \. Just for future reference ^^.

Also, that code does what I want, but the original question remains unanswered. I still want to know where I can find the in-depth Ant material.

I am asking because a previous task I wrote could only be done with Ant, and I had no idea that it could not easily be done with Gradle; however, it was very easy with Ant. A Gradle developer suggested I use ant.move. I didn’t know I could do that, I don’t know when I can do that in the future.

So my question is where can I found out how to do Ant tasks in-depth. Right now I have to search Ant documentation (which I never used before), see what is available to use, then do an advanced Github search of Gradle files that contain that task name, and see how it is used. I cannot go to any documentation in Gradle that I have found.

By the way, the Ant code for my original question is…

doLast {

    ant.copy(todir: sourceDir) {
        ant.fileset(dir: intelliJColorSchemeDir)
        ant.firstmatchmapper {
            ant.globmapper(from: "ChroMATERIAL IntelliJ IDEA.icls", to: "ChroMATERIAL.xml")
            ant.globmapper(from: "*.icls", to: "*.xml")

(Schalk Cronjé) #4

I share your pain. Try to work back from Ant docs to something that is usable in Gradle can be a bumpy road. It is not helped by the fact that the Ant are incomprehensible in places.