gpt4 book ai didi

java - Gradle - 使用以闭包作为参数的插件方法的语法错误

转载 作者:行者123 更新时间:2023-11-30 05:21:30 25 4
gpt4 key购买 nike

下面是 build.gradle 中的两个任务 helloprintProperties:

task('hello', {
description("Hey student! Run this one :D")
group("Our demo")
doLast({println("Hello World!")})
}
)

plugins({
id('java')
})

ext({
springVersion = "3.1.0.RELEASE"
emailNotification = "build@master.org"
})

sourceSets.all({ ext.purpose = null })

sourceSets({
main({
purpose = "production"
})
test({
purpose = "test"
})
plugin({
purpose = "production"
})
})

task('printProperties', {
doLast({
println(springVersion)
println(emailNotification)
sourceSets.matching({ it.purpose == "production" }.each({ println it.name }))
})
})
<小时/>

给出错误:

> startup failed:
build file '/../../build.gradle': 8:
only buildscript {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed
<小时/>

为什么plugins({id('java')})给出groovy脚本语法错误?

最佳答案

答案在这里:https://stackoverflow.com/a/48611069/1250435

Whenever you write a build.gradle script and use the new plugins script block, you need to put it as first block in the file. The only exceptions from this rule are other plugins blocks or the special buildScript block, which always must go first.

关于java - Gradle - 使用以闭包作为参数的插件方法的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59507030/

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