【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'
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/han1202012/article/details/126926980