Android Studio Bumblebee 新建项目模版build.gradle 如何添加 classpath plugins maven
Android Studio Bumblebee 新建项目模版build.gradle 如何添加 classpath plugins maven
前言
升级Android Studio Bumblebee后,发现新建项目时的根目录build.gradle已经和之前的完全不一样了。
旧的build.gradle如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.21"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
而新的build.gradle如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.5.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
可以看到classpath变成了plugins id,但是有很多就的库的描述还是使用classpath,那如何添加呢?
添加classpath
依旧和旧的build.gradle一样添加buildscript dependencies即可。
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath "com.yanzhenjie.andserver:plugin:2.1.9"
}
}
添加maven
添加maven则迁移到了根目录的setting.gradle文件中
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
// 添加maven
maven { url 'https://jitpack.io' }
}
}
rootProject.name = "My Application"
include ':app'