gpt4 book ai didi

gradle - 在缺少MissingMethodException的build.gradle中找不到自定义方法

转载 作者:行者123 更新时间:2023-12-03 04:02:08 25 4
gpt4 key购买 nike

尝试在build.gradle中调用自定义方法时遇到错误。

build.gradle文件中:

def func() {
String str = "hello world!"
str
}

buildscript {
repositories {
mavenCentral()
}

dependencies {
String str = func()
println "$str"

...... // Other code
}
}

我得到的错误如下:
Caused by: org.gradle.api.internal.MissingMethodException: Could not find method func() for arguments [] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@1c86d7b4.

最佳答案

buildscript {}闭包的所有洞察力都有不同的范围。我是个笨拙的家伙,无法真正解释原因-也许有人可以添加它。但是您可以实现目标的是在func中定义buildscript:

buildscript {
func = {
String str = "hello world!"
str
}

dependencies {
str = func()
println "$str"
}
repositories {
mavenCentral()
}
}

关于gradle - 在缺少MissingMethodException的build.gradle中找不到自定义方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36765850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com