Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring the inputs of a gradle task as multiple files

Tags:

android

gradle

We have a gradle task that will automatically generate codes for us before building. See the following as an example,

task djinniTask(type: org.gradle.api.tasks.Exec) {
    commandLine 'sh', './Djinni/run_djinni.sh'
}

assembleDebug.dependsOn djinniTask

Basically, the above run_djinni.sh is using a library djinni to generate JNI codes. The above works fine except that it will run this script every time we build even if we didn't update the script file, which is obviously not very efficient. We did a bit of research and found 17.9. Skipping tasks that are up-to-date. And as a result, the following works fine. It will skip this task if we didn't modify run_djinni.sh.

task transform {
    ext.srcFile = file('./Djinni/run_djinni.sh')
    ext.destDir = new File(buildDir, 'generated')
    doLast {
        commandLine 'sh', './Djinni/run_djinni.sh'
    }
}

Now the problem is, the run_djinni.sh is not the only script file that we have. The project is big and we multiple scripts files like: run_foo_djinni.sh, run_bar_djinni.sh and etc. run_djinni.sh will call each of the other scripts. So is there a way to declare the inputs of a gradle task as multiple files, for example, in our case, every files that is under the Djinni folder?

like image 373
Yuchen Avatar asked Oct 29 '25 08:10

Yuchen


1 Answers

Ok, according to gradle DSL you can define multiple inputs:

task transform {
   inputs.files('file path', 'another file path')
}
like image 85
Eugen Martynov Avatar answered Oct 31 '25 22:10

Eugen Martynov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!