Can I define kotlinVer either plugins or dependencies when I use Android Studio?

Viewed 79

I find there are two ways to define kotlin version in build.gradle (Project) based some sample projects, such as Code A and Code B.

Are they the same way? which one is better?

Code A

buildscript {
    ext {
        kotlinVer = '1.7.10'
        ...
    }
}

plugins {
     ...
    id 'org.jetbrains.kotlin.android' version "$kotlinVer" apply false
    
}

Code B

buildscript {
    ext {
       ...
    }

    repositories {
        google()
        mavenCentral()
    }

    dependencies {     
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
         ...
    }
}
1 Answers

Both serve the same purpose, and the reason they are different is because of newer Gradle upgrades from 7.1 upward. You can check out how it's done in the android Doc. here

Related