Could not find method leftShift() for arguments af

2020-01-30 06:24发布

After updating studio 3.4 and Gradle version to 5.1.1 I got the error on my task as Could not find method leftShift()

My task:

task incrementBetaVersion << {
    println("Incrementing Beta Version Number...")
    incrementVersionNumber('BetaVersionNumber')
    println("Incrementing Beta Version Number...")
    incrementVersionName('BetaVersionName')
}

I got the error for the left shift operator << in the line.

How to resolve this error?

4条回答
三岁会撩人
2楼-- · 2020-01-30 06:39

It happening because of the Left Shift operator has been replaced by doLast { }.

<< has deprecated in 4.x and removed in 5.0 version

Now you will have to change the code:

task incrementBetaVersion << {
    println("Incrementing Beta Version Number...")
    incrementVersionNumber('BetaVersionNumber')
    println("Incrementing Beta Version Number...")
    incrementVersionName('BetaVersionName')
}

to

task incrementBetaVersion  {
    doLast {
        println("Incrementing Beta Version Number...")
        incrementVersionNumber('BetaVersionNumber')
        println("Incrementing Beta Version Number...")
        incrementVersionName('BetaVersionName')
    }
}
查看更多
爷、活的狠高调
3楼-- · 2020-01-30 06:42

I had this error in a Kotlin project that is using MockMaker to mock non final classes.

The solution is to change the old syntax to this new one:

task createTestResources {
    description = "Allows Mocking non-final classes and data classes in a Kotlin project"
    doLast {
        def mockMakerFile = new File("$projectDir/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker")
        if (System.env.MOCK_MAKER != null) {
            logger.info("Using MockMaker ${System.env.MOCK_MAKER}")
            mockMakerFile.parentFile.mkdirs()
            mockMakerFile.createNewFile()
            mockMakerFile.write(System.env.MOCK_MAKER)
        } else {
            logger.info("Using default MockMaker")
        }
    }
}

Note that a few things have changed, like including the doLast block, and removing the << from the task signature. It works for me now. Hope it does for you too :-)

查看更多
相关推荐>>
4楼-- · 2020-01-30 06:44

<< (LeftShift()) operator is deprecated in 4.x Gradle and Removed in 5.x Gradle Version.

For solution of Could not find method leftShift() for arguments on task of type org.gradle.api.DefaultTask

Just Remove "<<" from Task and add method in doLast{}

Reference https://discuss.gradle.org/t/could-not-find-method-leftshift-for-arguments-on-task-of-type-org-gradle-api-defaulttask/30614/2

task incrementBetaVersion << {
   // your code
}

to

task incrementBetaVersion {
   doLast {
      // your code
    }
}
查看更多
我只想做你的唯一
5楼-- · 2020-01-30 06:59

To solve this error, change << with doLast like this.

task incrementBetaVersion  {
    doLast {
        println("Incrementing Beta Version Number...")
        incrementVersionNumber('BetaVersionNumber')
        println("Incrementing Beta Version Number...")
        incrementVersionName('BetaVersionName')
    }
}

Left shitf operator represent's doLast { }.

<< was deprecated in Gradle 4.x and removed in Gradle 5.0

From Docs:

<< for task definitions no longer works. In other words, you can not use the syntax

task myTask << { …​ }.

Use the Task.doLast() method instead, like this:

task myTask {
    doLast {
        ...
    }
}

More info here: https://discuss.gradle.org/t/could-not-find-method-leftshift-for-arguments-on-task-of-type-org-gradle-api-defaulttask/30614

https://docs.gradle.org/current/userguide/upgrading_version_4.html#changes_5.0

查看更多
登录 后发表回答