Passing arguments to a task

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