Is resource filtering in Gradle possible without using tokens?

后端 未结 3 1238
走了就别回头了
走了就别回头了 2020-12-29 06:34

The recommended way to do resource filtering in Gradle is by having tokens in the properties file and then replacing them when processing.

Example

#          


        
3条回答
  •  盖世英雄少女心
    2020-12-29 07:03

    You could use the following (not tested):

    processResources {
        filesMatching('**/config.properties') {
            filter {
                it.replace('localhost', project.property('myhost'))
            }
        }
    }
    

    Or you could have a default file, used during development in your IDE, and have another file containing tokens and replacing the development one when building using gradle. Something like this (not tested)

    processResources {
        exclude '**/config.properties'
        filesMatching('**/config-prod.properties') {
            setName 'config.properties'
            filter ReplaceTokens, tokens: [
                "myhost": project.property('myhost')
            ]
        }
    }
    

提交回复
热议问题