:wave: Any ideas on how I can convert this code bl...
# gradle
v
­čĹő Any ideas on how I can convert this code block to kts syntax?
build.gradle(project)- top level
Copy code
subprojects {
    afterEvaluate {
        if (project.hasProperty('android')) {
            android.buildTypes { project -> // This part
                debug {...}
                release{...}
                ... // Other build types
            }
        }
    }
}
v
The Kotlin DSL version should largely be the same. One point is, that you cannot use the type-safe accessor
android
as that only works with plugins you applied in the same script using the
plugins
DSL. This is mainly a hint that you should not do what you do. Using
afterEvaluate
is evil, except for rare cases, using
subprojects { ... }
or
allprojects { ... }
is evil, using the legacy
apply
to apply a plugin is evil. If you really insist on using that bad-practice style, you need to get the Android extension by type, for example
the<WhateverTypeTheAndroidExtensionHas>().buildTypes { ...}
or
configure<WhateverTypeTheAndroidExtensionHas> { buildTypes { ...} }
v
@Vampire Thanks for the feedback. How would you recommend that build variants are declared in a multimodule android project?
v
I don't do Android development. But if you mean what to use instead of
subprojects { ... }
, then use convention plugins, for example as precompiled script plugin, then apply the convention plugin where you want its effects to be present.