Calling a function declared in a third part gradle file from within the buildscript construct

て烟熏妆下的殇ゞ 提交于 2020-06-01 07:40:57

问题


I;m porting to Grade Kotlin Script the following:

buildscript {
    repositories {
        maven {
            url = URI("https://plugins.gradle.org/m2/")
        }
    }
    dependencies {
        apply(from = "https://raw.githubusercontent.com/i-net-software/SetupBuilder/master/scripts/SetupBuilderVersion.gradle")
        classpath("gradle.plugin.de.inetsoftware:SetupBuilder:" + setupBuilderVersion())
        classpath "gradle.plugin.io.sdkman:gradle-sdkvendor-plugin:1.2.1"
    }
}

where setupBuilderVersion() is a function defined in SetupBuilderVersion.gradle

I tried to declare val buildVersionName: groovy.lang.Closure<Any> by ext before the buildscript and within the dependencies but both failed to work (ext remains unresolved)

How can I solve it?


回答1:


buildscript {     
   repositories { 
        maven { url = uri("https://plugins.gradle.org/m2/") } 
   }
   apply(from = "https://raw.githubusercontent.com/i-net-software/SetupBuilder/master/scripts/SetupBuilderVersion.gradle") 
   val setupBuilderVersion = project.extensions.extraProperties["setupBuilderVersion"] as groovy.lang.Closure<*> 
   println(setupBuilderVersion()) 
}


来源:https://stackoverflow.com/questions/62092938/calling-a-function-declared-in-a-third-part-gradle-file-from-within-the-buildscr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!