如何在Gradle上检查buildscript插件的版本?

时间:2018-08-22 11:01:16

标签: gradle android-gradle gradle-plugin

我想通过编程方式了解gradle插件的版本,以便可以从脚本中进行检查。

1 个答案:

答案 0 :(得分:1)

您可以从Project界面使用“ buildscript”属性来访问buildScript的配置和依赖项,如下所示:

apply plugin: com.netflix.gradle.plugins.packaging.SystemPackagingPlugin

buildscript {
    ext {
        ospackagePluginVersion = '4.9.3'
    }
    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.netflix.nebula:gradle-ospackage-plugin:${ospackagePluginVersion}"
    }
}

println "Build script dependencies: "
buildscript.getConfigurations().getByName("classpath").getDependencies().each {
    Dependency dep ->
        println "Dependency : name=$dep.name in version : $dep.version"
        // do something with Dependency instance..
}

这将输出:

> Configure project :
Build script dependencies: 
Dependency : name=gradle-ospackage-plugin in version : 4.9.3