Gradle, overload extension setter

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.

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

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.

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.

Weird behaviour… I was using jdk1.8… Seems too unreliable to rely on.