# Passing arguments to a task

**URL:** https://discuss.gradle.org/t/passing-arguments-to-a-task/8427
**Category:** Help/Discuss
**Created:** [April 1, 2015, 6:14pm UTC](https://discuss.gradle.org/t/passing-arguments-to-a-task/8427 "2015-04-01T18:14:36Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)
#### Post date: [April 1, 2015, 6:23pm UTC](https://discuss.gradle.org/t/passing-arguments-to-a-task/8427/2 "2015-04-01T18:23:33Z")

</div>

If I understand you correctly, you basically want to create a bunch of tasks based on a “template”. You could create a method to do this which takes the properties as method arguments.

```
def tarArtifactTask(fromDir, toDir, baseName, buildTask) {
    return tasks.create("tar${baseName}Artifact", Tar) {
        compression = Compression.GZIP
        from fromDir {
            into toDir
        }
        extension = "tar.gz"
        baseName = baseName
        version = "${project.artifactVersion}"
        dependsOn buildTask
    }
}
```

---

_[View the full topic](https://discuss.gradle.org/t/passing-arguments-to-a-task/8427)._
