Is it possible to parametrize task? For example I want to create one zip task which will be used by two other tasks but those tasks needs to pass some additional information info this zip task (ex. zip name).
This is how I want it to work. If it is not possible, how can I do it? Or if I can is there some better solution?
task zipFile(type: Zip) {
from files('dist/zip')
destinationDir = file('dist')
archiveName = myArchiveName // myArchiveName should be passed as property
}
task zipTwoFiles << {
// create first archive
zipFile.execute() // how to pass property to this task?
// create second archive
zipFile.execute() // how to pass property to this task?
}
I want to do it because this is my first step in migrating project from ant to gradle. In ant it looks like this:
<target name="zipFile">
<zip destfile="dist/${myArchiveName}" basedir="dist/zip" />
</target>
<target name="zipFile1">
<antcall target="zipFile">
<param name="myArchiveName" value="myarchive.zip" />
</antcall>
<antcall target="zipFile">
<param name="myArchiveName" value="myarchive2.zip" />
</antcall>
</target>
Explicitly calling a task is not supported by Gradle. Instead, you should declare two Zip
tasks. If necessary, you can declare another task that has no behavior on its own but depends on the two Zip
tasks. Such a task is called lifecycle task.
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