-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ast transformation doesn't work in groovy-java project #178
Comments
This type of interoperability is not possible with current Groovy. Even if you compiled with bare groovyc it should fail. AST transforms that add methods late (I think after semantic analysis phase) like @builder, @TupleConstructor, @singleton and many others can only be used within the same project by Groovy sources. Your example would work if you split the builder into a separate project, so the Java source was forced to work with the .class of the builder. |
@eric-milles the groovy docs for @builder indicate that this is supposed to work so should this be considered a compiler bug or a documentation bug?
|
A lot of transforms like @builder are described in a purely Groovy context. They do certainly work as described Groovy to Groovy. But Groovy to Java interoperability does not work as you may intuit it does. I wish it worked as you described. And there is certainly a path in Groovy-Eclipse to make it work that way. The trouble is if we did something that the vanilla groovyc did not support, there would be a lot of problems. |
@eric-milles thanks, I guess I'll open an issue against the groovy project to fix the documentation then since it specifically suggests using the @builder transform for Java interop. |
If you want to use it today interoperably, you can create a separate project to hold the types that you want to use @builder or @immutable or whatnot on. Full compilation on the separate project allows the project you are in now to see complete class files instead of incomplete stub representations.
|
Thanks @eric-milles, that is one of the options we were considering. |
@eric-milles when you say "The trouble is if we did something that the vanilla groovyc did not support, there would be a lot of problems." then I say that it depends if that is trouble or not. I am working, with very low priority, on a compiler that can solve this kind of issue, but this would be also more than pure groovyc can do. And just because of that I don´t consider that compiler trouble. |
What I mean by that is if something works within Eclipse but fails as part of an Ant or Gradle or whatever build that leverages Groovyc, I consider that a problem. Certainly I understand the push for better compilers. At this time, if I find a difference between the Eclipse compiler and Groovyc, my instinct is to makes changes to ensure parity.
Within my workplace, we use Eclipse for Java/Groovy development and Ant for CI builds/deploys. So we look to have a consistent experience between how a project runs in the IDE and how it will compile and test on the CI server.
|
The problem is that our current joint compilation approach solves a lot of problems, but it is not a satisfying solution to me at all.
All of those I see as solvable doing a tighter integration with something that understands Java source code or can teach a Java compiler some Groovy. So really, if the differing feature is that groovy-eclipse supports transforms better than groovyc for joint compilation I am more than happy... of course only as long the compiler is also supported outside the IDE, yes. |
I don't like the current state of joint compilation and would very much like to see it improved. All the nicities that drew me to Groovy like @builder, @TupleConstructor, traits and so forth have a hard time playing with Java in the same project. If they worked as they are described in the groovydocs and demoed in a pure Groovy environment, the case for Groovy would be much stronger (around my workplace).
If groovy-eclipse can be a part of the move towards better joint compliation, that's great. I do see some bits of code that have been disabled because they offer more in terms of joint compilation support than groovyc does. I am reluctant to enable them without hearing from Andy Clement why exactly they were disabled. Similarly, retaining any functional difference from groovyc without some kind of compiler options seems dangerous as I described previously.
|
Can't compile my project
https://github.com/originalrusyn/mix/tree/greclipse
The text was updated successfully, but these errors were encountered: