工欲善其事, 必先利其器。
文章目录
- init.gradle.kts
- Groovy版本的init.gradle
- 其他有用的
- settings.gradle.kts
- kotlin 与 compose 版本对应关系
- agp 与 gradle 版本对应关系
- gradle下载器
直接在.gradle
文件夹下添加文件init.gradle
/ init.gradle.kt
for kotlin dsl.
如果同时存在init.gradle
和init.gradle.kt
,则优先按照init.gradle
中的配置,除非手动指定初始化脚本--init-script
init.gradle.kts
注:如果和groovy版本的init脚本同时存在,则会优先加载groovy版本的
fun RepositoryHandler.setPluginRepos(){maven("http://localhost:8001/repository/maven-plugins/"){isAllowInsecureProtocol=true}maven("https://maven.aliyun.com/repository/gradle-plugin")gradlePluginPortal()
}
fun RepositoryHandler.setDependenceRepos(){maven("http://localhost:8001/repository/maven-public/"){isAllowInsecureProtocol=true}maven("https://maven.aliyun.com/repository/public")maven("https://maven.aliyun.com/repository/central")maven("https://maven.aliyun.com/repository/jcenter")maven("https://maven.aliyun.com/repository/gradle-plugin")mavenCentral()mavenLocal()google()
}
settingsEvaluated {pluginManagement {repositories {setPluginRepos()}}dependencyResolutionManagement {repositories{setDependenceRepos()}}
}
Groovy版本的init.gradle
allprojects {buildscript{repositories {maven { name 'aliyunCentral' ; url 'https://maven.aliyun.com/repository/central' }maven { name 'aliyunJcenter' ; url 'https://maven.aliyun.com/repository/jcenter' }maven { name 'aliyunGoogle' ; url 'https://maven.aliyun.com/repository/google' }maven { name 'aliyunPlugin' ; url 'https://maven.aliyun.com/repository/gradle-plugin' }mavenCentral()mavenLocal()google()}}repositories {maven { name 'aliyunCentral' ; url 'https://maven.aliyun.com/repository/central' }maven { name 'aliyunJcenter' ; url 'https://maven.aliyun.com/repository/jcenter' }maven { name 'aliyunGoogle' ; url 'https://maven.aliyun.com/repository/google' }maven { name 'aliyunPlugin' ; url 'https://maven.aliyun.com/repository/gradle-plugin' }google()mavenLocal()}
}
其他有用的
settings.gradle.kts
pluginManagement {repositories {maven("http://localhost:8001/maven-public"){isAllowInsecureProtocol=true}maven("https://maven.aliyun.com/repository/public")maven("https://maven.aliyun.com/repository/central")maven("https://maven.aliyun.com/repository/jcenter")maven("https://maven.aliyun.com/repository/gradle-plugin")google()mavenLocal()mavenCentral()gradlePluginPortal()}
}dependencyResolutionManagement {repositories{maven("http://localhost:8001/maven-public"){isAllowInsecureProtocol=true}maven("https://maven.aliyun.com/repository/public")maven("https://maven.aliyun.com/repository/central")maven("https://maven.aliyun.com/repository/jcenter")maven("https://maven.aliyun.com/repository/gradle-plugin")google()mavenLocal()mavenCentral()}
}
kotlin 与 compose 版本对应关系
https://developer.android.google.cn/jetpack/androidx/releases/compose-kotlin
agp 与 gradle 版本对应关系
https://developer.android.google.cn/build/releases/gradle-plugin
gradle下载器
本文的国内源全局配置结合gradle下载器,让你的gradle项目编译更加丝滑
ComposeForDesktop之gradle下载器