Slackbot
12/07/2023, 8:51 PMAndrew Tasso
12/07/2023, 8:55 PMNamedDomainObjectContainer<Provider<String>> ?Kelvin Chung
12/07/2023, 8:57 PMProvider<String> is meant to be a name key to something in the container.Andrew Tasso
12/07/2023, 9:00 PMNamedDomainObjectContainer is keyed with a String. Would the Provider<String> be the source for that key?Kelvin Chung
12/07/2023, 9:00 PMAndrew Tasso
12/07/2023, 9:01 PMKelvin Chung
12/07/2023, 9:02 PMProvider<String>, and the container can produce Provider<T>, so I was looking for some map() or flatMap() operation on the name provider that gets around container.named() erroring out if there is no object of type T by that name in the container.Andrew Tasso
12/07/2023, 9:03 PMAndrew Tasso
12/07/2023, 9:15 PMnull?Kelvin Chung
12/07/2023, 9:15 PMProvider.isPresent == falseKelvin Chung
12/07/2023, 9:16 PMProvider.get() errors, Provider.getOrNull() returns null, etc.Andrew Tasso
12/07/2023, 9:42 PMnull if the key isn't found (depending on which method you use). There's no way to get it to produce anything else. Even the method which accept a configuration action fail if the key isn't found. So, in order to get what you want, you'd need to implement your own NamedDomainObjectContainer<T> or wrap calls to it in some code, which wouldn't be compliant with it's interface.Andrew Tasso
12/07/2023, 9:43 PMmap{} you referenced be called on?Kelvin Chung
12/07/2023, 9:43 PMProvider.map()Andrew Tasso
12/07/2023, 9:43 PMKelvin Chung
12/07/2023, 9:44 PMval result: Provider<T> = nameProvider.flatMap { container.named(it) }
but not erroring if named() errors out.Andrew Tasso
12/07/2023, 9:46 PMnameProvider is of type Provider<String> ?Kelvin Chung
12/07/2023, 9:47 PMAndrew Tasso
12/07/2023, 9:57 PMmap not being able to accept a String isn't an issue with the Kotlin version, but rather that result is declared using a generic. Since you're passing it to findByName it assumes that it is a String, which is why it's complaining.Andrew Tasso
12/07/2023, 9:58 PMit needs to be of type TAndrew Tasso
12/07/2023, 10:00 PMKelvin Chung
12/07/2023, 10:01 PMval nameProvider: Provider<String> = ...
val container: NamedDomainObjectContainer<T> = ...
val result: Provider<T> = ...?Andrew Tasso
12/07/2023, 10:01 PMAndrew Tasso
12/07/2023, 10:07 PMproject object?Kelvin Chung
12/07/2023, 10:08 PMAndrew Tasso
12/07/2023, 10:14 PMProvider<String> and you're looking for a more generic Provider<T> and you can't change the type of the provider with the inbuilt transform methods.Kelvin Chung
12/07/2023, 10:18 PMfun <R, T> Provider<T>.map(fn: T -> R?): Provider<R>
fun <R, T> Provider<T>.flatMap(fn: T -> Provider<R>?): Provider<R>
(note: on older versions of Gradle, the return type of fn is not nullable)Andrew Tasso
12/07/2023, 10:19 PMAndrew Tasso
12/07/2023, 10:19 PMAndrew Tasso
12/07/2023, 10:24 PMAndrew Tasso
12/07/2023, 10:27 PMAndrew Tasso
12/07/2023, 10:31 PMAndrew Tasso
12/07/2023, 10:34 PMAndrew Tasso
12/07/2023, 10:37 PMKelvin Chung
12/07/2023, 10:37 PMmap() and flatMap() need to return non-nullable values from the Kotlin API. (I am aware that Gradle 8 fixed it.)Andrew Tasso
12/07/2023, 10:39 PMAndrew Tasso
12/07/2023, 10:39 PMAndrew Tasso
12/07/2023, 10:41 PMefemoney
12/08/2023, 3:23 AMefemoney
12/08/2023, 3:25 AMmyProvider.map { if (it !in namedContainer.names) null else it } or if on Gradle 8.4/5 myProvider.filter { it in namedContainer.names }efemoney
12/08/2023, 3:27 AM(Iโm using an older version of Gradle where the Kotlin API says thatIts there even in the newer versions of Gradle, its an issue with the API declaration, see a workaround here https://github.com/slackhq/slack-gradle-plugin/blob/aed728664ab35501b27c0e6979b228[โฆ]/slack-plugin/src/main/kotlin/slack/gradle/util/PropertyUtil.ktcanโt take amap)String -> T?
Vampire
12/08/2023, 11:15 AMVampire
12/08/2023, 11:15 AMVampire
12/08/2023, 11:15 AM121333: Executing 'help'...
Type-safe project accessors is an incubating feature.
> Configure project :
task ':build'
null
> Task :help
Welcome to Gradle 7.6.3.