<< is a shortcut for calling Task.doLast {}. doLast{} adds an action to the task, which will be performed during the task execution phase. Task dependencies are resolved before the task execution phase begins, which is why you get an error saying that you cannot change the task dependencies.
Okay for this snippet, When I have the dolast function the script does not compile. The ones with it will do what it is written. Why is that? if I remove the << it also compiles.
task EnabledUser(type: Zip) << {
from (‘hdm/function’)
include 'cloudUIEnabledUserTag.*'
archiveName 'cloudUIEnabled.zip’
destinationDir file(‘dist/hdm/function’)
}
task FirmwareMatch(type: Zip) {
from (‘hdm/function’)
include 'factoryResetOnFirmwareMatch.*'
archiveName 'factoryResetOnFirmwareMatch.zip’
destinationDir file(‘dist/hdm/function’)
}
task CloudUI(type: Zip)<< {
from (‘hdm/function/4.0.2’)
include 'cloudUIEnabledUserTag.*'
archiveName 'cloudUIEnabled.zip’
destinationDir file(‘dist/hdm/function/4.0.2’)
My recommendation is to stop using <<. It ultimately just causes people confusion.
The general structure of a task definition looks like this:
task nameOfTask {
// configuration time code
println 'this is happening at configuration time'
// one of the many methods available in all task classes is dependsOn
dependsOn someOtherTask
// available methods are determined by the task's type
// one of the other methods available is doLast
doLast {
println 'this is happening at execution time'
}
}
I recommend spending some time going through the user guide, as I think it will help a lot. The user guide uses << a lot, but again I recommend avoiding it, especially when learning Gradle. I suggest starting with sections 14 and 17 of https://docs.gradle.org/current/userguide/pt03.html if you want to learn more about tasks.