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

前端 未结 2 1510
时光取名叫无心
时光取名叫无心 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 12:51

    Now (Gradle 2.3.1) there is a better solution: https://issues.gradle.org/browse/GRADLE-1566

    processResources {
        inputs.property('version', version)
        filesMatching("**/version.properties") {
            expand version: version
        } }
    

    In my case I want project properties expansion only in yaml files:

    processResources {
        filesMatching("**/*.yaml") {
            expand project.properties
        }
    }
    
    0 讨论(0)
  • 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 )
    }
    
    0 讨论(0)
提交回复
热议问题