DataDog / dd-sdk-android-gradle-plugin

The Datadog Gradle Plugin for Android
Apache License 2.0
14 stars 9 forks source link

Provide example for variants configuration with Kotlin DSL #154

Closed thomasflad closed 11 months ago

thomasflad commented 1 year ago

Hi DataDog Team,

I'm struggling with setting up a configuration per variant in a Kotlin Script Gradle file. Can you provide an example how it should look like?

datadog {
    site = "US" // Variants with no configurations will use this as default
    variants {
        fr {
            site = "EU"
            mappingFilePath = "path/to/fr/mapping.txt"
        }
    }
}
0xnm commented 1 year ago

Hello @thomasflad! Thanks for reporting this issue, indeed variants property configuration is not compatible with Kotlin DSL.

When using Groovy, it is capable to doing some conversions thanks to the meta-programming capabilites.

Kotlin DSL on another hand is statically typed, so some things should be more explicit. For the moment, the example you posted will look like following in Kotlin DSL:

datadog {
    site = "US"
    withGroovyBuilder {
        "variants" {
            "create"("fr") {
                setProperty("site", "EU")
                setProperty("mappingFilePath", "path/to/fr/mapping.txt")
            }
        }
    }
}

Here I used withGroovyBuilder which may not look nice, but at least does the job. Alternatively you can write configuration in Groovy and apply it using dynamic-groovy-plugin.

In the meantime we will do the necessary changes to be compatible with Kotlin DSL for variants property and will try to ship the fix soon.