Gradle zip plugin, How to create empty folder with

2020-04-14 07:04发布

问题:

I have the follow Gradle task which does packaging. In which it produces a zip file. However I am trying create a empty folder call log within the zip file as part of final distribution.

task package(type: Zip){
   into('/log') {
  }
}

The above code does not work and I have tried

def destDir = new File(buildDir, 'log/log')
    destDir.mkdir()

and then copy

into('/') {
 from "$buildDir/log"
}

Problem with that is if I run gradle clean package it clear out the build folder which cause the log folder not created. Does anyone have a solution to the problem of creating an empty folder within the zip distribution we are trying to create?

回答1:

I do something like this:

package.doFirst {
    new File(buildDir, 'log/log').mkdirs()
}