I have a task that i want to run at the very end of the build, i have this model
project.gradle.addListener new DependencyCheckListener() {
def allTasks
@Override
void graphPopulated(TaskExecutionGraph graph) {
allTasks = graph.allTasks
}
@Override
void buildFinished(BuildResult result) {
println("trying to fire the dependency check")
dependencyCheck.execute()
}
}
Now, this code runs perfectly fine, but i get the nag saying that the execute method is going to be eliminated in 5. so i change it to this:
project.gradle.addListener new DependencyCheckListener() {
def allTasks
@Override
void graphPopulated(TaskExecutionGraph graph) {
allTasks = graph.allTasks
}
@Override
void buildFinished(BuildResult result) {
println("trying to fire the dependency check")
dependencyCheck.dependencyUpdate() //this is the @TaskAction annotated method of the task
}
}
and the task blows up. about 5 classes deep, i get class not found errors for ivy version comparator initialization.
what is different between these two methods? How am i supposed to execute a task in the buildFinished event in v5?
unfortunately it does. This isn’t my code, and i can’t refactor it. But the task needs access to gradles configuration system, ivy systems and such. Basically its checking the dependencies of the project once a day and printing a report to alert of things being out of date.
Why does the check task need to run at the end of the build? Does it fail when it runs while other tasks are running? Or is it just so that the output does not get lost?
If it really depends on all the other task you could just add a dependency on those tasks - so the dependencyCheck will run after all the other tasks.
This is in the same class as nebula gradle lint. When the code is done, I want this task to run once a day to notify the developer that their libs are out of date. Just like autolint from nebula, I want this as a depends on the build, not another task because not all tasks are avail in all builds in my shop. The ultimate would be
is check avail in all builds? even ones without the java plugin applied? if its a native app, without the java plugin applied, is check still avail? what about the Cobol plugin i have an intern writing, he is starting from scratch on it and not using the java plugin as a base because its so radically different, does that have the check task?
the goal is to make this dependency check task universal across the 20 or so languages we have. I have no guarantee that many of these tasks will be available. for example our cobol plugin won’t have a build task because the concept of build doesn’t exist, thats a mainframe function. all the plugin is going to do is static analysis.
I also love the fact that in nebula, the lint is the last thing displayed on the screen. I find that a lot of my developers prefer to use the --console=plain command so they can see exactly whats going on. a typical build in my shop has over 150 tasks in it. this dependency report would get lost in the output.
but the issue comes a little deeper, what is the point of the listener system if you can’t use it to execute a task?
@scphantm The check task is added by the LifecycleBasePlugin which is added by the BasePlugin. All language plugins should apply the base plugin, so check should be available.
Regarding displaying the interesting information at the end: You can still add an action to buildFinished which prints out the result of the check task. The task itself can run any time.
Ok, we may be on to something here. does check get fired every time in the workflow? Regardless of what task is run? Meaning if I create mytask, is the check task executed as well?