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

**URL:** <https://discuss.gradle.org/t/in-depth-documentation-for-more-advanced-gradle-based-ant-targets/23928>\
**Category:** Help/Discuss\
**Created:** [August 30, 2017, 6:08am UTC](https://discuss.gradle.org/t/in-depth-documentation-for-more-advanced-gradle-based-ant-targets/23928 "2017-08-30T06:08:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ciscorucinski](https://avatars.discourse-cdn.com/v4/letter/c/67e7ee/32.png) [@ciscorucinski](https://discuss.gradle.org/u/ciscorucinski)\
**Post date:** [August 30, 2017, 6:08am UTC](https://discuss.gradle.org/t/in-depth-documentation-for-more-advanced-gradle-based-ant-targets/23928/1 "2017-08-30T06:08:27Z")

</div>

##Summary  
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.

## Background

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…

1. [https://docs.gradle.org/current/userguide/ant.html](https://docs.gradle.org/current/userguide/ant.html),
2. [https://docs.gradle.org/current/userguide/tutorial\_using\_tasks.html#sec:using\_ant\_tasks\_tutorial](https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:using_ant_tasks_tutorial),
3. [https://docs.gradle.org/current/javadoc/org/gradle/api/AntBuilder.html](https://docs.gradle.org/current/javadoc/org/gradle/api/AntBuilder.html)

## Code

```
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!")

}
```

---

<div class="post-metadata">

**Author:** ![Schalk\_Cronje](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schalk_cronje/32/6511_2.png) [@Schalk\_Cronje](https://discuss.gradle.org/u/Schalk_Cronje)\
**Post date:** [August 31, 2017, 3:53pm UTC](https://discuss.gradle.org/t/in-depth-documentation-for-more-advanced-gradle-based-ant-targets/23928/2 "2017-08-31T15:53:29Z")

</div>

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`.

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

```

---

<div class="post-metadata">

**Author:** ![ciscorucinski](https://avatars.discourse-cdn.com/v4/letter/c/67e7ee/32.png) [@ciscorucinski](https://discuss.gradle.org/u/ciscorucinski)\
**Post date:** [September 7, 2017, 7:07am UTC](https://discuss.gradle.org/t/in-depth-documentation-for-more-advanced-gradle-based-ant-targets/23928/3 "2017-09-07T07:07:18Z")

</div>

> [@Schalk\_Cronje](#):
>
> ```
> rename '(.+)\\.icls', '$1.xml'
> 
> ```

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")
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![Schalk\_Cronje](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schalk_cronje/32/6511_2.png) [@Schalk\_Cronje](https://discuss.gradle.org/u/Schalk_Cronje)\
**Post date:** [September 14, 2017, 10:06am UTC](https://discuss.gradle.org/t/in-depth-documentation-for-more-advanced-gradle-based-ant-targets/23928/4 "2017-09-14T10:06:03Z")

</div>

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.
