gradle / gradle

Adaptable, fast automation for all
https://gradle.org
Apache License 2.0
16.79k stars 4.7k forks source link

Unclear message when ValueSource parameters are accessed for a source with None parameters #30182

Open alllex opened 2 months ago

alllex commented 2 months ago

Consider the following snippet:

abstract class MyValueSource : ValueSource<String, ValueSourceParameters.None> {
    override fun obtain(): String? {
        println("Parameters: $parameters")
        return "foo"
    }
}

This currently fails with:

> org.gradle.internal.service.UnknownServiceException: No service of type ValueSourceParameters$None available in value source services.
  > No service of type ValueSourceParameters$None available in value source services.

There seems to be no contract for accessing the parameters for a value source that has ValueSourceParameters.None, e.g. in any of the javadocs.

It is currently forbidden by failing, but there seems to be no reason why this shouldn't be supported.

There are at least two use-cases:


Build scan: https://ge.gradle.org/s/yxps2f3m5husm/failure#1

alllex commented 2 months ago

We have other Parameters-like concepts, the UX for which should ideally be the same:

mlopatkin commented 2 months ago

This feature request is in the backlog of the relevant team and is prioritized by them.


We should make all aforementioned places (and BuildServiceParameters) behave in the same way. Preferrably, we should allow getting None instances in both getParameters and when registering/configuring, just for simplicity of the contract.

big-guy commented 2 months ago

+1 for removing the specialness of None.