Gradle Copy files and expand only some of them and/or ignore dollar signs in others

前端 未结 2 1509
时光取名叫无心
时光取名叫无心 2021-01-12 12:04

I have a tree of files that I\'d like to copy with Gradle, and for some of the files (e.g. ending in .txt), I\'d like to do some property substitions. For example, I have:<

2条回答
  •  再見小時候
    2021-01-12 13:02

    Thanks to the link from Opal in the comments, I found a solution. The link shows that it is possible to have multiple from sources and each of these can have a separate expand treatment. Thus, in my case, I only wanted to expand .txt files, so I split the from into two parts using include & exclude as follows:

    task "copyAndroidAssets$flavor" (type: Copy, 
        dependsOn: ["cleanAndroidAssets", "copyAndroidRes$flavor"] ) {
        from ("build/assets/${flavorLc}/release/") {
            include '**/*.txt'
            expand ( versionName: versionName, versionCode: versionCode )
        }
        from ("build/assets/${flavorLc}/release/") {
            exclude '**/*.txt'
        }
        into '../android/assets'
        expand ( versionName: myVersionName, versionCode: myVersionCode )
    }
    

提交回复
热议问题