Gradle Plugin: How to set autoUpload based on build type

I’d like to set sentry.autoUpload to true for release builds and false for debug builds. I’m finding this surprisingly difficult – eg I tried:

buildTypes {
    getByName("release") {
        sentry {
            autoUpload.set(true)
        }
    }
    getByName("debug") {
        sentry {
            autoUpload.set(false)
        }
    }
}

but both buildTypes blocks are executed regardless of the current build type.

I could do something like:

sentry {
    gradle.startParameter.taskNames.any {
        it.endsWith("Release")
    }.let {
        autoUpload.set(it)
    }
}

but that seems rather brittle.

What’s the recommended approach here?