gradle: unsorted dependsOn tasks, how to handle?
I have three stages on my installation routine:
1) download 2) unzip 3) configure
downloads, use ant.get and ant.checksum, so I build my own DownloadTask class, and then in the build:
task download (type: DownloadTask) {
url = url
checksumAlgorithm = 'MD5'
destFile = zipFile
}
so I came with 4 tasks:
task download {...}
task unzip {...}
task configure {..}
task install(dependsOn: [download, unzip, configure]) {}
But I get noticed that dependsOn don't respect the sort order,开发者_高级运维 http://issues.gradle.org/browse/GRADLE-427
So.. how is the workaround here?
I cannot move only this tasks as methods, because download it uses my DownloadTask class. I can move all as methods (even DownloadTask), but don't seems the best solution here.
Thanks
Well, you also can call your dependencies by hand if this is any help for you:
task install << {
download.execute()
unzip.execute()
configure.execute()
}
I do not think that this is the real Gradle idea, but for my multi-project build this worked quite well.
Greetings,
Jan
As tim mentioned you could configure your build to have these dependencies. What do you mean with "reusing" the tasks? You can use autowiring here instead of using the dependsOn property.
Autowire means, that you declare the output of task download as the input for the unzip task and so on. In your example above the url would be the input of your Download task and the destFile is the output. This approach makes it easy to reuse each task and makes explicit ordering unnecessary. In chapter 14.8 of the gradle userguide you can find a brief introduction to this kind of autowiring (http://www.gradle.org/current/docs/userguide/more_about_tasks.html#N10D4D). Have a look at the Javadoc about TaskInputs and TaskOutputs (mentioned in this chapter) too.
regards, René
精彩评论