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

Posted 韩曙亮

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android Gradle 插件Gradle 依赖管理 ⑩ ( dependencies 依赖配置项 configurations )相关的知识,希望对你有一定的参考价值。

文章目录

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 中 , 函数原型如下 :

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 闭包 作为参数 ;


配置示例 :

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'

以上是关于Android Gradle 插件Gradle 依赖管理 ⑩ ( dependencies 依赖配置项 configurations )的主要内容,如果未能解决你的问题,请参考以下文章