我有一个依赖于另一个项目的 Gradle 构建项目。我的项目应该从另一个项目中提取一个 zip 存档并提取存档。存档中的一个文件称为“name.txt”,里面是一个字符串,我需要在“构建”任务中将其作为参数传递。
def unzippedDir = file('build/dependencies/unzippedDir').getAbsolutePath()
configurations {
zipArchive
}
dependencies {
ziparchive "<path>"
}
task unzip(type:Copy) {
into unzippedDir from zipTree(configurations.zipArchive.singleFile)
}
task build {
dependsOn unzip
def name = new File(unzippedDir + '/name.txt').text
// <the test of the build steps that uses the "name" variable>
}
Run Code Online (Sandbox Code Playgroud)
但是我收到“name.txt”的“无文件或目录”错误。难道我做错了什么?
但是,我在提取的目录中看到的是,zip 存档中只有一个文件最终出现在 unzippedDir 中。即使另一个文件存在,“name.txt”也不存在。这是否意味着我在解压缩任务上做错了什么?