gradle buildscript "name" 变量分辨率不工作
gradle buildscript "name" variable resolution not working
以下是我的build.gradle
的内容
class Human {
Integer age;
String name;
String surName;
Human(name, age, surname) {
this.name = name;
this.age = age;
this.surName = surname;
}
def executeInside(Closure c) {
c.delegate = this
c()
}
}
def h1 = new Human("John", 43, "Smith");
def hc = {
println "My name is ${name} and my age is ${age} and my surname is ${surName}"
}
h1.executeInside(hc)
hc.delegate = h1
hc()
执行脚本时,我应该得到 My name is John and my age is 43 and my surname is Smith
但是我却得到了
My name is mygradlefoldername and my age is 43 and my surname is Smith
如果我 运行 在 groovyConsole
中使用上面的脚本,它可以正常工作,但是在这个 gradle 构建脚本中发生了什么导致名称没有正确打印?
名称已被保留且正确指向项目目录:
https://docs.gradle.org/current/userguide/writing_build_scripts.html
将 Human class 中的 属性 名称更改为类似 firstName 的名称,这样就可以了
以下是我的build.gradle
class Human {
Integer age;
String name;
String surName;
Human(name, age, surname) {
this.name = name;
this.age = age;
this.surName = surname;
}
def executeInside(Closure c) {
c.delegate = this
c()
}
}
def h1 = new Human("John", 43, "Smith");
def hc = {
println "My name is ${name} and my age is ${age} and my surname is ${surName}"
}
h1.executeInside(hc)
hc.delegate = h1
hc()
执行脚本时,我应该得到 My name is John and my age is 43 and my surname is Smith
但是我却得到了
My name is mygradlefoldername and my age is 43 and my surname is Smith
如果我 运行 在 groovyConsole
中使用上面的脚本,它可以正常工作,但是在这个 gradle 构建脚本中发生了什么导致名称没有正确打印?
名称已被保留且正确指向项目目录:
https://docs.gradle.org/current/userguide/writing_build_scripts.html
将 Human class 中的 属性 名称更改为类似 firstName 的名称,这样就可以了