Skip to content

ProviderFactory#gradleProperty does not work for project-local properties #13302

@ZacSweers

Description

@ZacSweers

Expected Behavior

It should work

Current Behavior

It does not. Property is always considered "not present"

Context

I am trying to use the new ProviderFactory#gradleProperty() APIs to better prepare for configuration caching.

Steps to Reproduce

Repro case:

This project + branch: https://github.com/ZacSweers/CatchUp/compare/z/gradlePropertyIssueDemo?expand=1

In app/build.gradle.kts there are two properties used, one local to app and the other local to the whole project.

val localProperty = providers.gradleProperty("localProperty").orElse("not found")
val rootProperty = providers.gradleProperty("rootProperty").orElse("not found")

println("Local property is ${localProperty.get()}")
println("Root property is ${rootProperty.get()}")

Run ./gradlew help

Observe that the local property is not found and only the root project is

> Configure project :app
Local property is not found
Root property is rootPropertyValue

I would expect that the localProperty would be found. If I manually do it like so

val localProperty = providers.provider { property("localProperty")?.toString() }.orElse("not found")

it works

> Configure project :app
Local property is localPropertyValue
Root property is rootPropertyValue

This is with Gradle 6.4.1. I gave it a try on 6.5-rc-1, but to no avail. A slight change is that 6.5 doesn't allow resolving those at configuration time, but with a simple dummy task:

val localProperty = providers.gradleProperty("localProperty").orElse("not found")
val rootProperty = providers.gradleProperty("rootProperty").orElse("not found")

abstract class DummyTask : DefaultTask() {

  @get:Input abstract val localPropertyProp: Property<String>
  @get:Input abstract val rootPropertyProp: Property<String>

  @TaskAction
  fun act() {
    println("Local property is ${localPropertyProp.get()}")
    println("Root property is ${rootPropertyProp.get()}")
  }
}

tasks.register<DummyTask>("testingThingsOut") {
  localPropertyProp.set(localProperty)
  rootPropertyProp.set(rootProperty)
}

And then running ./gradlew testingThingsOut

> Task :app:testingThingsOut
Local property is not found
Root property is rootPropertyValue

Still no dice :/

Your Environment

Build scan URL:

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugThis doesn't work as expectedclosed:duplicateDuplicated or superseeded by another issuein:configuration-modellazy api, domain object containerin:provider-apiproperty lazy provider MapProperty ListProperty DirectoryProperty

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions