本文主要记录Groovy版本和kotlin版本的Gradle 相关设置。以便备忘或以后迁移参考。
settings.gradle
settings.gradle
:
pluginManagement {
// 所有Gradle插件的下载远程仓库地址
repositories {
gradlePluginPortal()
//google()
//mavenCentral()
// 阿里云镜像
maven {
url 'https://maven.aliyun.com/repository/central' }
maven {
url 'https://maven.aliyun.com/repository/public' }
maven {
url 'https://maven.aliyun.com/repository/jcenter' }
maven {
url 'https://maven.aliyun.com/repository/google' }
maven {
url 'https://maven.aliyun.com/repository/releases' }
maven {
url 'https://maven.aliyun.com/repository/snapshots' }
maven {
url 'https://maven.aliyun.com/repository/gradle-plugin' }
}
}
dependencyResolutionManagement {
// 所有模块依赖库的下载远程仓库地址
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
//google()
//mavenCentral()
// 阿里云镜像
maven {
url 'https://maven.aliyun.com/repository/central' }
maven {
url 'https://maven.aliyun.com/repository/public' }
maven {
url 'https://maven.aliyun.com/repository/jcenter' }
maven {
url 'https://maven.aliyun.com/repository/google' }
maven {
url 'https://maven.aliyun.com/repository/releases' }
maven {
url 'https://maven.aliyun.com/repository/snapshots' }
maven {
url 'https://maven.aliyun.com/repository/gradle-plugin' }
}
}
rootProject.name = "My Application"
include ‘:app’
settings.gradle.kts
:
pluginManagement {
// 所有Gradle插件的下载远程仓库地址
repositories {
gradlePluginPortal()
//google()
//mavenCentral()
// 阿里云镜像
maven(url = "https://maven.aliyun.com/repository/central")
maven(url = "https://maven.aliyun.com/repository/public")
maven(url = "https://maven.aliyun.com/repository/jcenter")
maven(url = "https://maven.aliyun.com/repository/google")
maven(url = "https://maven.aliyun.com/repository/releases")
maven(url = "https://maven.aliyun.com/repository/snapshots")
maven(url = "https://maven.aliyun.com/repository/gradle-plugin")
}
}
dependencyResolutionManagement {
// 所有模块依赖库的下载远程仓库地址
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
//google()
//mavenCentral()
// 阿里云镜像
maven(url = "https://maven.aliyun.com/repository/central")
maven(url = "https://maven.aliyun.com/repository/public")
maven(url = "https://maven.aliyun.com/repository/jcenter")
maven(url = "https://maven.aliyun.com/repository/google")
maven(url = "https://maven.aliyun.com/repository/releases")
maven(url = "https://maven.aliyun.com/repository/snapshots")
maven(url = "https://maven.aliyun.com/repository/gradle-plugin")
}
}
rootProject.name = "My Application"
include ‘:app’
推荐使用阿里云的Maven镜像仓库地址,下载速度很快。
根目录 build.gradle
build.gradle
:
ext {
sdkVersion = 33
appcompatVersion = "1.6.0"
...
}
plugins {
// apply false只能用于顶层build.gradle文件,切勿写在子模块中
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.21' apply false
}
build.gradle.kts
:
ext {
extra["sdkVersion"] = 33
extra["appcompatVersion"] = "1.6.0"
...
}
plugins {
// apply false只能用于顶层build.gradle文件,切勿写在子模块中
id("com.android.application") version "7.3.1" apply false
id("com.android.library") version "7.3.1" apply false
id("org.jetbrains.kotlin.android") version "1.7.21" apply false
}
子模块 build.gradle
build.gradle
:
plugins {