-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task.onlyIf, cacheIf, setEnabled should accept Provider<Boolean>
#16080
Comments
Actually, another workaround is to do
So that the lambda is more self contained. But yes, definitely |
Note that this workaround above will miss a build logic input. It should be: project.tasks.register<MyTask>("task") {
val foo = project.providers.gradleProperty("foo")
onlyIf { foo.isPresent }
} 👍 on having |
Hi folks, I hit this problem too and would appreciate any feedback if my workaround is ok. The last workaround is better but only applicable to In my case, I was accessing a boolean property from my extension. I resolved it by assigning the extension to a "redundant" local variable. GradleUp/auto-manifest#14 |
To be more precise, the scenario that this issue affects is when the lambda that is SAM-converted to a It does not reproduce under the following conditions:
The example in the original issue description does not seem to reproduce the issue in the modern Gradle versions as-is, unless some additional conditions are created. |
Provider<Boolean>
Note to implementer: The provider should be able to carry task dependencies. |
Using Gradle 6.8+, consider a plugin:
because of the way kotlin compiles lambdas, it will create a lambda that contains a reference to the outer scope of the
onlyIf
lambda, which will include the plugin instance. This will most often break as plugins are allowed to use non serializable types such as projects, tasks, etc.See : https://stackoverflow.com/q/44538627/693752
as a workaround, one can create a subclass of
Spec
that accepts a boolean as a constructor parameter and pass an instance of this class toonlyIf
, so that there is no leak of the plugin instance.To solve this, it would be nice to be able to provide an overload of onlyIf that would accept a provider of boolean.
The text was updated successfully, but these errors were encountered: