How to expand property references in jar resources?

前端 未结 5 1914
挽巷
挽巷 2021-01-12 06:47

I\'m using Gradle to build a jar containing an xml file in META-INF. This file has a row like



        
5条回答
  •  逝去的感伤
    2021-01-12 07:06

    here is what worked for me (Gradle 4.0.1) in a multi-module project:

    in /webshared/build.gradle:

    import org.apache.tools.ant.filters.*
    
    afterEvaluate {
        configure(allProcessResourcesTasks()) {
            filter(ReplaceTokens,
                    tokens: [myAppVersion: MY_APP_VERSION])
        }
    }
    
    
    def allProcessResourcesTasks() {
        sourceSets*.processResourcesTaskName.collect {
            tasks[it]
        }
    }
    

    and my MY_APP_VERSION variable is defined in top-level build.gradle file:

    ext {
    
        // application release version.
        // it is used in the ZIP file name and is shown in "About" dialog.
        MY_APP_VERSION = "1.0.0-SNAPSHOT"
    }
    

    and my resource file is in /webshared/src/main/resources/version.properties :

    # Do NOT set application version here, set it in "build.gradle" file
    # This file is transformed/populated during the Gradle build.
    version=@myAppVersion@
    

提交回复
热议问题