gradle问题记录

在使用<< 的时候报错

运行代码

task printmyFirstGradlewProject   <<  {
    def firstStr = 'zm first String named kabasiji' // 不用分号
    def secondStr = "zm baobao second String"

    println()
    println(firstStr)
    println('${firstStr}')
    println("引用str : ${firstStr}")

    println()
    println(secondStr)
    println('${secondStr}')
    println("引用str : ${secondStr}")
}

报错:
Caused by: org.gradle.internal.metaobject.AbstractDynamicObject_run_closure1@395c3053] on task ':app:printmyFirstGradlewProject' of type org.gradle.api.DefaultTask.

原因 : << 语法(等同于dolast效果) 在gradle 4中被弃用, 在gradle 5中被彻底删除 , 所以会报错;
解决方案: 使用dolast 即可

task printmyFirstGradlewProject  {
    doLast{
        def firstStr = 'zm first String named kabasiji' // 不用分号
        def secondStr = "zm baobao second String"

        println()
        println(firstStr)
        println('${firstStr}')
        println("引用str : ${firstStr}")

        println()
        println(secondStr)
        println('${secondStr}')
        println("引用str : ${secondStr}")
    }
}

你可能感兴趣的:(gradle问题记录)