Gradle: Replace Tokens by finding the tokens from property file

前端 未结 1 1089
既然无缘
既然无缘 2020-12-29 12:11

Currently I understand that we can use org.apache.tools.ant.filters.ReplaceTokens to replace the contents of a file during build in the following way.

<

相关标签:
1条回答
  • 2020-12-29 12:32

    you can pass properties as a map to the ReplaceTokens configuration. The key must match the token you want to see replaced. Example:

    beans.xml:

    <bean id="mybean1" class="com.test.MyClass1" >
        <property name="myprop1" value="@myproperty@" />
    </bean>
    

    my.properties:

    myproperty=testme
    

    build.gradle:

    task myCopy(type:Copy){
        from "bean.xml"
        into ("$buildDir/beans")
        def myProps = new Properties()
        file("my.properties").withInputStream{
            myProps.load(it);   
        }
        filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: myProps)
    }
    

    hope that helped.

    cheers, René

    0 讨论(0)
提交回复
热议问题