2017-06-30 183 views
0

我有一个Gradle构建项目依赖于另一个项目。我的项目应该从另一个项目中提取zip文件并提取存档。存档内的一个文件名为“name.txt”,里面有一个字符串,我需要在我的“构建”任务中作为参数传递。Gradle,提取依赖zip和使用其文件中的内容?

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> 
} 

但是我得到了一个“没有文件或目录”错误的“name.txt”。难道我做错了什么?

我在提取的目录中看到的是,只有一个ZIP压缩文件内的文件以unzippedDir结尾。即使是另一个文件,“name.txt”也不存在。这是否意味着我做了解压缩任务的错误?

+0

我在提取的目录中看到的是,只有一个ZIP压缩文件内的文件结束了unzippedDir。即使是另一个文件,“name.txt”也不存在。这是否意味着我做了解压缩任务的错误? – JimmyT

回答

1

试试这个:

和检查,因为拼写错误有你的配置名称。

def unzippedDir = "$buildDir/dependencies/unzippedDir" 

task unzip(type: Copy) { 
    configurations.zipArchive.asFileTree.each { 
     from(zipTree(it)) 
    } 
    into unzippedDir 
} 

build.dependsOn unzip 
+0

这是否意味着我必须将archiveDir指向存储依赖项归档的位置?哪里是? – JimmyT

+0

@JimmyT archive dir是您的档案所在的目录。我不知道你在哪里。 – LazerBanana

+0

存档从工厂存储库中被下拉。它通过gradle自动存储在某个地方。所以我不知道它在哪里。 – JimmyT

0

尝试:

task build { 
    dependsOn unzip 
    doLast { 
     def name = new File(unzippedDir + '/name.txt').text 
     <the test of the build steps that uses the "name" variable> 
    } 
}