# Tar command using Exec (using source FileCollection in command line)

**URL:** <https://discuss.gradle.org/t/tar-command-using-exec-using-source-filecollection-in-command-line/30203>\
**Category:** Help/Discuss\
**Created:** [January 17, 2019, 12:57pm UTC](https://discuss.gradle.org/t/tar-command-using-exec-using-source-filecollection-in-command-line/30203 "2019-01-17T12:57:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpbostock](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@mpbostock](https://discuss.gradle.org/u/mpbostock)\
**Post date:** [January 17, 2019, 12:57pm UTC](https://discuss.gradle.org/t/tar-command-using-exec-using-source-filecollection-in-command-line/30203/1 "2019-01-17T12:57:31Z")

</div>

When using the Tar task in Gradle to create a tar.gz, Gradle does not support symbolic links. I therefore wanted to try and override the Tar task within the distribution plugin to run an Exec and manually run the tar command.  
I currently have the following (some common files in main, os specific files in linux/windows folders):

```
distributions {
    main {
        contents {
            ...
        }
    }
    linux {
        contents {
            with(main.contents)
            ...
        }
    }
    windows {
        contents {
            with(main.contents)
            ...
        }
    }
}

tasks.withType(Tar) {
    actions = []
    doLast {
        exec {
            mkdir "${destinationDir}"
            executable "tar"
            args "-czvf"
            args "${destinationDir}/${archiveName}"
            args source.files
    }
}

```

When I build I only run the linuxDistTar task on a Linux machine  
But this throws an error:  
`Cannot run program "tar" (in directory "..."): error=7, Argument list too long`

I think it’s because the source.files is giving all the files from the original Tar task as a space separated list and there are a lot of files.

Is there a way of getting the root directory of a source list and using that? Or do I need to extract source into a dummy folder then pass dummyFolder/\* as the last argument?

I’m using Gradle 3.5.1 if that helps.
