I have a case statement inside one of my groovy fi...
# gradle
j
I have a case statement inside one of my groovy file's plugins that uses a lambda I'm not sure how to reproduce in Kotlin
Copy code
appToken { ApplicationVariant variant ->
        switch (variant.buildType.name) {
            case 'develop': 'XXXX'
                break
            case 'release': 'YYYY'
                break
        }
    }
How can I access the same specific ApplicationVariant? The only thing I could think of was to use
android.applicationVariants.first()
, but I get Build Failure error: Collection is empty.
e
What exactly are you trying to configure? What is
appToken
in the snippet above? Searching a bit on the interwebs I guess https://docs.bugsee.com/sdk/android/crashes/, correct?
j
Yeah, that's the one. It's a string.
e
Looking into it,
appToken
is a function from the bugsee plugin that takes a Groovy Closure expecting one parameter (the variant) and returning a string.
Please ask bugsee authors to provide a type safe way to configure their plugin, something like
appToken(Transformer<String, BaseVariant>)
would do.
In the meantime you can use the Groovy interop utilities of the Gradle Kotlin DSL:
Copy code
bugsee {
    appToken(KotlinClosure1<BaseVariant, String>({
        when(buildType.name) {
            "develop" -> "XXXX"
            "release" -> "YYYY"
            else -> "ZZZZ"
        }
    }))
}
👍 1