This is a regression between Gradle 2.7 and 2.8 that caused the J2ObjC Gradle Plugin to fail. The plugin liberally uses @CompileStatic to enforce compile time checks. In this case, it appears that @CompileStatic is allowing code to fail at runtime that should have failed at compile time. The failure occurs with this line:
Note that replaceAll is a String method which StringGroovyMethods doesn’t have. If you remove @CompileStatic from the class, then it runs just fine, presumably doing automatic type conversion from GroovyString to regular String. When you add @CompileStatic and make the type conversion explicit by adding toString() then it also runs fine…
So the issue is with @CompileStatic, why didn’t fail at compile time when toString() was missing? That’s the crux of this issue. I don’t have good insights beyond this. Nonetheless, since it’s a regression between Gradle 2.7 and 2.8, it deserves to be better understood.
daz, sterling - thanks for your insights. I think it’s appropriate to let this one go and not to do anything about it.
If I compile the plugin with Gradle 2.8 and then run a build using the plugin with 2.8, then it all works fine. So it’s only when you compile the plugin with 2.4 and then do the build with 2.8 do you have an issue. After adding the toString(), then the build works fine with 2.4 and 2.8.
To be clear, it’s something that should not have been done in Groovy. The irony is that it’s only because we wanted to improve static compilation that this happens: sticking with dynamic Groovy, there wouldn’t have been an issue! I will send an email to the Groovy dev list to warn about such changes. We already have a task in the Groovy build that checks for binary incompatibilities, not enforced yet because the tool we use is not 100% reliable.