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

标签 java gradle groovy build.gradle

下面是 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/

相关文章:

c# - .Net UI 和 Java 中间件

java - 使用 SAXParser 解析 XML 文件

java - Android Studio 2.2,Gradle 构建失败,出现 java.lang.OutOfMemoryError : unable to create new native thread

java - Android TextView 左右对齐文本

java - 使用 POI 从 Excel 工作表的下一行获取值

intellij-idea - 使用 Gradle (JetGradle) 和 Intellij Idea 13 提供依赖项

android - Gradle 恶魔启动数百个虚拟机

jenkins println 输出中的 Groovy-script 在类环境中调用时消失

grails - 多个联接的排序问题

javascript - SOAPUI:SIMple Groovy 脚本 - 导入语句存在语法错误?