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 to copy it I had to save it somewhere - thats why I went for solution: copy to temp location while replacing lines > delete original file > copy duplicated file back to original place > delete temp file. Is there better solution?
If the task you want to pass parameters to is of type JavaExec and you are using Gradle 5, for example the application plugin's run task, then you can pass your parameters through the --args=... command line option. For example gradle run --args="foo --bar=true" .
Gradle supports two types of task. One such type is the simple task, where you define the task with an action closure. We have seen these in Build Script Basics. For this type of task, the action closure determines the behaviour of the task. This type of task is good for implementing one-off tasks in your build script.
To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we'll use “-x test” to skip tests from the build. As a result, the test sources aren't compiled, and therefore, aren't executed.
gradle files are the main script files for automating the tasks in an android project and are used by Gradle for generating the APK from the source files.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With