Distributions - strip top level directory

Is there a way to strip a top level directory when creating a distribution archives using the distribution plugin?

My config:

distributions {
    main {
        baseName = 'my_app'
        contents {
            from {
                "$buildDir/distribution-files/application"
            }
        }
    }
}

And after I issue:

gradle distZip

The resulting archive has a top level directory with the same name as the archive itself:

my_app-1.0.0.zip
    my_app-1.0.0
        contents

And I must deliver the package as follows:

my_app-1.0.0.zip
    contents
2 Likes

Try this:

distributions {
    main {
        baseName = 'my_app'
        contents {
            from {
                "$buildDir/distribution-files/application"
            }
            eachFile { FileCopyDetails fcp ->
              fcp.relativePath = new RelativePath(true, fcp.relativePath.pathString.replace('my_app-1.0.0/', ''))
            }
        }
    }
}

Naah. I found a better solution:

distributions {
    main {
        baseName = 'my_app'
        contents {
            from {
                "$buildDir/distribution-files/application"
            }
            into '/'
        }
    }
}

The following attribute is the key here:

into '/'

But thanks anyway.

4 Likes