Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use gradle to run the touch command on a file

Tags:

gradle

touch

I have a build.gradle file that runs a series of tasks before building my android APK. I looked through the documentation but I didn't find an answer so I'll ask here. Is it possible - and if it is how - to run the touch command on a file using gradle?

like image 309
James andresakis Avatar asked Feb 11 '23 23:02

James andresakis


2 Answers

It has been some time since this question was answered. I think there is a more elegant way available in Gradle as of today.

Remembering that Gradle treats Ant as a first class citizen, you can invoke any ant task as a simple method call using Groovy syntax.

Ant has a touch task and in Gradle you can invoke it easily as shown below. For reference on the parameters supported by the Ant Touch task look here: https://ant.apache.org/manual/Tasks/touch.html

task testStuff(){
   ant.touch(file:"some.properties")
}
like image 184
pczeus Avatar answered Feb 14 '23 12:02

pczeus


You just need to create a task of type Exec and pass appropriate configuration. See the docs.

like image 31
Opal Avatar answered Feb 14 '23 12:02

Opal