以下是hello中的两个任务printPropertiesbuild.gradle:

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 = "[email protected]"
})

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

09-11 20:44