Centril
(Mazdak Farrokhzad)
November 4, 2014, 8:03pm
1
I posted a question regarding getting
GroovyCastException
for overloaded setters for extension properties (for a plugin) in gradle @ stackoverflow - however, the answers don’t really address the problem.
http://stackoverflow.com/questions/26730867/gradle-overload-extension-setter
PS: I know this is kinda double posting & I apologize for that…
Simply put, this works in Gradle versions 2.0+. I’ve posted this as an answer on SO.
Centril
(Mazdak Farrokhzad)
November 4, 2014, 11:04pm
3
Not true…
Try the following code in Gradle 2.1 in a random build.gradle file…
class Foo {
Project proj
void setProject( Project project) {
this.proj = project
}
void setProject( String project) {
println 1337;
}
}
project.extensions.create('foo', Foo)
foo {
project = ':random-project'
}
It gives me:
http://pastebin.com/eTPZnCLG
luke_daley
(Luke Daley)
November 4, 2014, 11:06pm
4
This is a limitation of the Groovy language: https://jira.codehaus.org/browse/GROOVY-3632
That is very strange. The exact snipped that Mazdak posted above works for me in Gradle 2.1. Executing something like ‘gradle tasks’ prints ‘1337’ to the screen.
Centril
(Mazdak Farrokhzad)
November 5, 2014, 12:24am
6
Luke Daley: Bummer! Thanks for the info, at least now I know it can’t be done =)
Update: I was able to reproduce the failure Mazdak is seeing when using a Java8 JRE. Going back to Java7 seems to work, perhaps though, only incidentally.
Update: Disregard, in that case it simply always calls the ‘String’ setter.
Centril
(Mazdak Farrokhzad)
November 5, 2014, 8:30am
8
Weird behaviour… I was using jdk1.8… Seems too unreliable to rely on.