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.