How do I dynamically configure a dependency (inside a task) and then download the artifact?

I am trying to build a gradle plugin, which will does the following:

  1. As part of one its tasks, it creates a new configuration 2. It adds a DefaultExternalModuleDependency to this configuration - more specifically, it constructs a dependency to the application server zip file (available on Nexus). This information can be overridden by the invoking project as well. 3. Tries to resolve this newly added dependency and then unpacks the file to a local folder

All of this was working well when I had the details hard coded in a build file, but it looks like adding dependencies as part of a task are not treated the same way as having that information available at the parsing time.

So my question is, how do I get the project to reload the configurations / dependencies?

The code looks like the following:

@TaskAction
void installAppserver() {
  Dependency dependency = new DefaultExternalModuleDependency(group,name,version)
  Configuration configuration = project.configurations.detachedConfiguration(dependency)
  configuration.setTransitive(false)
  configuration.files.each { file ->
    if (file.isFile() && file.name.endsWith('.zip')) {
      println 'Attempting to unzip: ' + file + ' into folder: ' + appServerFolder
      new Copy().from(project.zipTree(file)).into(appServerFolder).execute()
    }
  }
}

The problem is that the actual artifacts are not getting resolved!

Thanks

Already answered on Stack Overflow. Please don’t double-post.

Hi Peter,

I didn’t realize that you guys were monitoring StackOverflow as well. Will keep that in mind the next time I have a query in Gradle.

Thanks, Harsha