本文介绍了从buildscript构造中调用在第三部分gradle文件中声明的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将以下内容移植到Grade Kotlin脚本:

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"
    }
}

其中setupBuilderVersion()SetupBuilderVersion.gradle

我尝试在buildscript之前和dependencies内声明val buildVersionName: groovy.lang.Closure<Any> by ext,但是两者均无法正常工作(ext仍未解决)

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)

我该如何解决?

推荐答案

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())
}

这篇关于从buildscript构造中调用在第三部分gradle文件中声明的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 07:10