Jim*_*myT 4 gradle build.gradle
我有一个依赖于另一个项目的 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”也不存在。这是否意味着我在解压缩任务上做错了什么?
尝试这个:
并检查您的配置名称,因为那里有拼写错误。
def unzippedDir = "$buildDir/dependencies/unzippedDir"
task unzip(type: Copy) {
configurations.zipArchive.asFileTree.each {
from(zipTree(it))
}
into unzippedDir
}
build.dependsOn unzip
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11448 次 |
| 最近记录: |