[Feature Request] - Create emty directories in a TAR File

plugins

(Marvin Strangfeld) #1

Hi,

I would like to create some empty directories inside a TAR file. Is there any possibility to implement something like this?

build.gradle.kts

tasks.register("myTar", Tar::class.java) {
    it.mkdir("someDir/myEmptyDir")
}

Or does anybody know a workaround for this?


(Chris Doré) #2

Here’s a quick test of a workaround (in Groovy):

task tarWithEmptyDirs( type: Tar ) {
    archiveName = 'empties.tar'
    from( 'build.gradle' ) // include at least one file, else the task does not run because it has "no source"

    File empties = new File( temporaryDir, 'emptyDirs' )
    empties.deleteDir() // start fresh, we don't want dirs from previous task runs
    empties.mkdirs()
    ['empty1', 'empty2'].each {
        new File( empties, it ).mkdir()
    }
    from( empties )
}

$ tar -tf empties.tar
build.gradle
empty2/
empty1/