Gradle task replace string in .java file

前端 未结 3 1194
醉话见心
醉话见心 2020-12-03 10:31

I want to replace few lines in my Config.java file before the code gets compiled. All I was able to find is to parse file through filter during copying it. As soon as I have

3条回答
  •  无人及你
    2020-12-03 11:00

    May be you should try something like ant's replaceregexp:

    task myCopy << {
        ant.replaceregexp(match:'aaa', replace:'bbb', flags:'g', byline:true) {
            fileset(dir: 'src/main/java/android/app/cfg', includes: 'TestingConfigCopy.java')
        }
    }
    

    This task will replace all occurances of aaa with bbb. Anyway, it's just an example, you can modify it under your purposes or try some similar solution with ant.

提交回复
热议问题