Search code examples
spring-bootgradlebuild.gradlegradle-plugingradlew

How to modify the file on the fly while copying from one location to other in gradle


I want to modify the contents of file while making the .jar out of it. To do so i am trying to modify the "processResources" task like below -

processResources{
    println 'process resources..'
    from('./dist'){
        into('static')
    }

}

Here i have some html files under "dist" folder which I want to modify while copying it into .jar I have copied the file but didn't get any solution to modify the file while copying.

This is spring boot project along with gradle build tool.

Any help much appreciated!!


Solution

  • Found the nice documentation which covers the file operations in gradle in great details- https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch01.html

    the solution to my problem is like this >>

    processResources{
        println 'process resources..'
        from('./dist'){
    
            into('static')
    
            filter{
                line -> line.replace("old-string","new-string")
                 }
        }
    
    }