Task in plugin executes function too soon (during configuration) how can I delay it to execution?

Hi

I’ve created a custom plugin for our build system. In this plugin I defined a task of type: Download (from these guys: de.undercouch.gradle.tasks.download.Download). I have a function in another class which goes out to our Artifactory server and determines the latest artifact in the repo for the project. This however is an expensive call as it issues a REST query and has to roll through the results. This wasn’t a problem when I had manually specified the Download task in all of my sub-projects. But now that I’ve created a Plugin and moved the task into it this function is executed for every sub-project during the configuration phase when it is assigned to the src property of the Download plugin.

There has got to be some better way to prevent this from happening at config time right?

The original task in each sub-project looked like this:

download {
  src Utils.getLatestArtifact()
  dest $destDir
}

And in the plugin it looks more like this:

private void addAppTasks(Project project) {
  project.task('bundleArtifacts', type: Download) {
    src Utils.getLatestArtifact()
    dest $destDir
  }
}

Any ideas on how to fix this?

Thanks, Derek

You can try
download<<{

}
But I’m afraid it won’t work. If you want to keep using the download task, you have to stick to how it is used. I’m afraid you can’t move everything to a doLast Block inside the download task.

You might investigate if your “Utils.getLatestArtifact()” call could be changed to effectively look for the latest artifacts lazily.
What’s inside this method?

Or create a custom subtask of the download task in your plug-in.
This subtask would take your REST string as input, but effectively execute it only inside its @TaskAction method.