Could not find method leftShift() for arguments [build_2ilw3op988tm86o4ko1xhgbm0$_run_closure1@42805

学习Gradle时编写示例代码报错

示例代码如下:

task startSession << {
	chant()
}
def chant() {
	ant.echo(message: 'Repeat after me...')
}
3.times{
	task "yayGradle$it" << {
		println 'Gradle rocks'
	}
}

yayGradle0.dependsOn startSession
yayGradle2.dependsOn yayGradle1, yayGradle0
task groupTherapy(dependsOn: yayGradle2)

运行报错:

PS D:\Gradle> gradle groupTherapy

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\Gradle\build.gradle' line: 1

* What went wrong:
A problem occurred evaluating root project 'Gradle'.
> Could not find method leftShift() for arguments [build_2ilw3op988tm86o4ko1xhgbm0$_run_closure1@42805226] on task ':startSession' of type org.gradle.api.DefaultTask.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

编译版本如下:

PS D:\Gradle> gradle -v

------------------------------------------------------------
Gradle 6.1.1
------------------------------------------------------------

Build time:   2020-01-24 22:30:24 UTC
Revision:     a8c3750babb99d1894378073499d6716a1a1fa5d

Kotlin:       1.3.61
Groovy:       2.5.8
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          1.8.0_181 (Oracle Corporation 25.181-b13)
OS:           Windows 10 10.0 amd64

查出问题

代码中的<<在gradle5.1之后废弃了

解决方案

将<<改为doLast

task startSession {
	doLast{
		chant()
	}
}
def chant() {
	ant.echo(message: 'Repeat after me...')
}
3.times{
	task "yayGradle$it" {
		doLast{
			println 'Gradle rocks'
		}
	}
}

yayGradle0.dependsOn startSession
yayGradle2.dependsOn yayGradle1, yayGradle0
task groupTherapy(dependsOn: yayGradle2)

运行结果:

PS D:\Gradle> gradle groupTherapy

> Task :startSession
[ant:echo] Repeat after me...

> Task :yayGradle0
Gradle rocks

> Task :yayGradle1
Gradle rocks

> Task :yayGradle2
Gradle rocks

BUILD SUCCESSFUL in 1s
4 actionable tasks: 4 executed
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值