前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Android Gradle 插件】Gradle 依赖管理 ⑩ ( dependencies 依赖配置项 configurations )

【Android Gradle 插件】Gradle 依赖管理 ⑩ ( dependencies 依赖配置项 configurations )

作者头像
韩曙亮
发布2023-03-30 16:26:24
1.1K0
发布2023-03-30 16:26:24
举报
文章被收录于专栏:韩曙亮的移动开发专栏

文章目录

Android Plugin DSL Reference 参考文档 :

一、Android Gradle 插件中注册的依赖分组


添加构建依赖项 参考文档 : https://developer.android.google.cn/studio/build/dependencies

在这里插入图片描述
在这里插入图片描述

二、dependencies 依赖配置项 configurations


org.gradle.api.Project 配置 ( build.gradle 根配置 ) 文档 : https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html

可以通过 configurations 配置 dependencies 依赖配置项 , Android 默认配置好了一批依赖配置项 , 如

  • implementation
  • api
  • compileOnly
  • runtimeOnly
  • annotationProcessor
  • lintChecks
  • lintPublish
  • apk
  • compile
  • provided

这些配置也可以自定义 ;

configurations 配置 定义在了 org.gradle.api.Project 中 , 函数原型如下 :

代码语言:javascript
复制
void configurations​(Closure configureClosure)
Configures the dependency configurations for this project.

This method executes the given closure against the ConfigurationContainer for this project. 
The ConfigurationContainer is passed to the closure as the closure's delegate.

传入一个 Closure 闭包 作为参数 ;

配置示例 :

代码语言:javascript
复制
configurations {
    myconfig {

    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    myconfig 'androidx.appcompat:appcompat:1.4.1'
}
在这里插入图片描述
在这里插入图片描述
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-09-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 一、Android Gradle 插件中注册的依赖分组
  • 二、dependencies 依赖配置项 configurations
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档