Expected Behavior
If I have a provider used in a task, it should not test presence during configuration
Current Behavior
It does, and results in an exception
Caused by: java.lang.IllegalStateException: Cannot obtain value from provider of environment variable 'USER' at configuration time.
Use a provider returned by 'forUseAtConfigurationTime()' instead.
Context
I want to use an environmentVariable provider and want to default it if absent.
Steps to Reproduce
Drop this into a build.gradle.kts file
val userProvider = project.providers.environmentVariable("USER")
.orElse(project.provider { "absent" })
abstract class TestTask : DefaultTask() {
@get:Input
abstract val userProp: Property<String>
@TaskAction
fun printUser() {
println(userProp.get())
}
}
project.tasks.register<TestTask>("testTask") {
userProp.set(userProvider)
}
Then run ./gradlew testTask
You'll see this failure
Could not determine the dependencies of task ':testTask'.
> Cannot obtain value from provider of environment variable 'USER' at configuration time.
Use a provider returned by 'forUseAtConfigurationTime()' instead.
Your Environment
Build scan URL:
Expected Behavior
If I have a provider used in a task, it should not test presence during configuration
Current Behavior
It does, and results in an exception
Context
I want to use an environmentVariable provider and want to default it if absent.
Steps to Reproduce
Drop this into a build.gradle.kts file
Then run
./gradlew testTaskYou'll see this failure
Your Environment
Build scan URL: