cjtkirk
(hw.kirk)
May 20, 2014, 9:32pm
1
I want to declare a task that will be run once after all multiproject tasks finish.
(and not run after EACH task).
In other words, printArtifactDependencies should run ONCE and only once in the example below.
I think its actually sufficient to simply run once before gradle exits.
Any advice is appreciated.
project.task(‘gatherArtifactDependencies’) {
group ‘RUP’
doLast {
project.allprojects.each { proj ->
proj.configurations.each { conf ->
conf.allDependencies.findAll { it.group && it.group == project.getProperty(CONSUMING_GROUP_KEY) }.each { dep ->
RupBasePlugin.dependencyList << new Dependency( dep.name )
}
}
}
}
}
project.task(‘printArtifactDependencies’) {
group ‘RUP’
doLast {
logger.lifecycle "Final size is ${dependencyList.size()} "
}
}
// does not work. I want this task to run after ALL gatherArtifactDependencies tasks for all projects have finished
project.printArtifactDependencies.dependsOn(‘gatherArtifactDependencies’)
Easiest solution is to put such logic into ‘gradle.buildFinished {}’, rather than into a task.
cjtkirk
(hw.kirk)
May 21, 2014, 12:34pm
3
Sorry, I think my wording was not clear above.
I want the logger.lifecycle to run only when printArtifactDependencies task is executed and only after gatherArtifactDependencies has already run.
Using gradle.buildFinished {} would always run on any build (if I understand it correctly).
I should also mention this logic is going inside a custom plugin.
I don’t understand. I can only spot a single ‘gatherArtifactDependencies’ task that iterates over all projects.
cjtkirk
(hw.kirk)
May 21, 2014, 1:54pm
5
Correct.
gatherArtifactDependencies task iterates over all projects (and accumulates all dependencies into a list).
Once the above completes I want to print out the size of the list and perform other processing on the list.
The overall goal is simply to gather all the dependencies across all subprojects so I can work with the list in memory.
Although gatherArtifactDependencies is declared once, it executes once PER PROJECT.
Which was a surprise.
So if you think I am headed down a wrong path, I am happy to reverse course and rethink my approach.
Thanks very much
I don’t see why ‘project.printArtifactDependencies.dependsOn(‘gatherArtifactDependencies’)’ wouldn’t work then (as long as you run ‘gradle printArtifactDependencies’). You could also do the printing right inside ‘gatherArtifactDependencies’.
cjtkirk
(hw.kirk)
May 22, 2014, 12:31pm
7
I am not sure either.
I will say that the same code works inside build.gradle.
But not from our custom plugin.
Thank you, Peter.
I will have to re-think my strategy.