The Android Studio's Empty Activity default configuration calls the plugin function in two places:
in the FirstEmpty/build.gradle.kts script:
import org.gradle.kotlin.dsl.support.compileKotlinScriptModuleTo // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { alias(libs.plugins.androidApplication) apply false alias(libs.plugins.jetbrainsKotlinAndroid) apply false }
and in the FirstEmpty/app/build.gradle.kts script:
plugins { alias(libs.plugins.androidApplication) alias(libs.plugins.jetbrainsKotlinAndroid) }
plugins is defined in KotlinBuildScript, which will be deprecated:
Deprecated
Will be removed in Gradle 9.0
plugin is supposed to be replaced by apply:
If you need to apply a plugin imperatively, please use
apply()orapply(plugin = "id")instead.project(":core") { apply(plugin = "java") }
The above quote and the following statement make me believe that the plugins call can be replaced with an apply call with no repercussions on the rest of the script:
The
plugins {}block serves a similar purpose to theapplymethod that can be used to apply a plugin directly to aProjectobject or similar. A key difference is that plugins applied via theplugins {}block are conceptually applied to the script, and by extension the script target. At this time there is no observable practical difference between the two approaches with regard to the end result.
Please show me how to do it in this particular case.