使用AntBuilder在Groovy中压缩文件/目录

使用AntBuilder在Groovy中压缩文件/目录,ant,groovy,antbuilder,Ant,Groovy,Antbuilder,我正在尝试使用AntBuilder在Groovy中压缩文件和目录。我有以下代码: def ant = new AntBuilder() ant.zip(basedir: "./Testing", destfile:"${file}.zip",includes:file.name) 这将压缩文件“blah.txt”,但不会压缩文件“New Text Document.txt”。我认为问题在于空间。我尝试了以下方法: ant.zip(basedir: "./Testing", destfile:"

我正在尝试使用AntBuilder在Groovy中压缩文件和目录。我有以下代码:

def ant = new AntBuilder()
ant.zip(basedir: "./Testing", destfile:"${file}.zip",includes:file.name)
这将压缩文件“blah.txt”,但不会压缩文件“New Text Document.txt”。我认为问题在于空间。我尝试了以下方法:

ant.zip(basedir: "./Testing", destfile:"${file}.zip",includes:"${file.name}")
ant.zip(basedir: "./Testing", destfile:"${file}.zip",includes:"\"${file.name}\"")
上述两项都没有解决这个问题。我使用Ant是因为它会压缩目录,而我在工作时没有访问org.apache.commons.io.compression的权限。

如果您查看,includes参数描述为:

必须包含的文件模式的逗号或空格分隔列表

所以你是对的,是空间分隔符打破了它

您需要使用更长的路线来实现此功能:

new AntBuilder().zip( destFile: "${file}.zip" ) {
  fileset( dir: './Testing' ) {
    include( name:file.name )
  }
}

让我们了解一下您的环境(操作系统、Groovy版本等)