Configurations and Dependency resolution

I am in the process of developing a plugin to package our software and am trying to understand dependencies using configurations. The provider of a file has the following configuration

configurations {
    container
}

DownloadArtifact downloadContainer = tasks.findByName('download') as DownloadArtifact
artifacts {
    container downloadContainer.destFileProperty
}

(the download task is defined in the plugin) with the dependent project having a configuration of

configurations {
    containerSource
}

dependencies {
    containerSource project(path: ':container', configuration: 'container')
}

the dependent project shows the dependency

containerSource
\--- project :container

In a separate plugin from the container plugin, I have the following task configuration closure

project.tasks.create(...) {
    ...
    artifactProperty = project.configurations.containerSource.getSingleFile()
}

However, the task does not list the source project, container, as a dependency (using Doron Gold’s task tree plugin)

:services:emailservice:installContainer
\--- :services:emailservice:createDirectories

Notice that the task download (or as I have labeled it above ‘downloadContainer’) of project container is missing.

I believe I am missing a step, but not sure where. I have taken a look at some of the Gradle-provided plugins but believe the dependency wiring happens “automagically”. Thanks for your help.

This resolves configurations.containerSource at configuration time and turns it into a File (which loses all dependency information).

The easiest thing to do is make artifactProperty a FileCollection and do the call to getSingleFile() in your task action.

Thanks Sterling–you are spot on. As you suggested, once artifactProperty was a FileCollection the dependency was established.

I have also not been able to establish a dependency using a Property. The examples within the Lazy Configuration section of the User Guide work fine, but I must declare the dependencies in the task using dependsOn. Is there a similar pattern for properties? As an example

projects.tasks.create(...) {
    dependsOn = [ aTask ]

    inputFileProperty = aTask.outputFileProperty
}

Thanks again for your help!

My first guess would be to make sure the outputFileProperty is created with newOutputFile() and inputFileProperty is created with newInputFile().

https://docs.gradle.org/current/userguide/lazy_configuration.html#sec:working_with_task_dependencies_in_lazy_properties