0

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() or apply(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 the apply method that can be used to apply a plugin directly to a Project object or similar. A key difference is that plugins applied via the plugins {} 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.

1 Answer 1

0

No changes are needed to your build: that is a best practice project layout.

plugins in those instances is not defined in KotlinBuildScript anymore but in KotlinProjectScriptTemplate.

The plugins block from there is very much in use and is recommended in preference to using the apply method. The apply method does not add the plugin to your build classpath and does not give the script access to Kotlin DSL accessors.

Sign up to request clarification or add additional context in comments.

8 Comments

I don't get the message in Android Studio, the message is on the official Gradle documentation site. Android Studio is running fine on Gradle 8. Maybe when Gradle is updated, Android Studio Gradle scripts will also be updated and I should not bother.
That makes no sense to me. How do you get an error message on a documentation site?
I don't get an error message. The quoted text is from the Gradle documentation.
Ah, I see. You are just looking at the documentation for an old class representing the build script. I've updated the answer.
When I hover the mouse over plugins in FirstEmpty/build.gradle.kts in Android Studio, the infotip says: org.gradle.kotlin.dsl.KotlinBuildScript. How do you know that KotlinProjectScriptTemplate.plugins is called there instead of KotlinBuildScript.plugins?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.