Gradle,如何检索默认资源目录以添加文件

时间:2018-04-23 11:51:05

标签: gradle

所以,我正在尝试自动下载openvr kotlin port的本地库。

使用Gradle-Download-Task我设法下载本机(到构建目录):

task downloadNatives {
    doLast {
        // download directory listing via GitHub API
        def dirBin = 'https://api.github.com/repos/ValveSoftware/openvr/contents/bin'
        def content_linux32 = new File(buildDir, "directoryContents_linux32.json")
        download {
            src "$dirBin/linux32"
            dest content_linux32
        }        // parse directory listing
        def contents_linux32 = new groovy.json.JsonSlurper().parseFile(content_linux32, "utf-8")

        // download files
        download {
            src contents_linux32.collect { it.download_url }
            dest "buildDir/linux32"
        }

现在我想将它们放在默认的资源目录下,即src/main/resources

我尝试使用这些:

    println sourceSets.main.getResources()
    println sourceSets.main.resources

但没有太大的成功..

那么,我应该使用什么呢?

1 个答案:

答案 0 :(得分:1)

首先,在第二个download块中,buildDir只是一个字符串而不是变量。

然后,您可以将文件下载到主资源目录:

download {
    src contents_linux32.collect { it.download_url }
    dest sourceSets.main.resources.srcDirs[0]
}
相关问题