Skip to content
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

Groovy-Eclipse appears to interfere too much with Gradle projects #1053

Closed
Mrodent opened this issue Mar 4, 2020 · 7 comments
Closed

Groovy-Eclipse appears to interfere too much with Gradle projects #1053

Mrodent opened this issue Mar 4, 2020 · 7 comments

Comments

@Mrodent
Copy link

Mrodent commented Mar 4, 2020

Sorry, me again! I promise I'll give it a rest after this.

NB I can also imagine that anything to do with Groovy must be very high-level technical stuff... and when you throw Java 11 in the mix this must make things even worse.

My latest problem is described here on SO.

Essentially, I am finding that by including the following (essential!) line in build.gradle, a completely inexplicable (to me) "AST transform" error is cropping up:

testImplementation 'org.spockframework:spock-core:1.2-groovy-2.5'

As I say at the end, really the "workspace level" of Groovy should not get involved with Gradle projects at all, since they use configured versions of Groovy, both to execute build.gradle and the DSL, and also the user code (if written in Groovy with the Groovy plugin in build.gradle).

And yet, of course, something must be involved in analysing the Groovy code in my project: otherwise I wouldn't have detection of (real) errors, code completion, syntax colouring, etc.: the component which does this is your module Groovy-Eclipse (for which I thank you).

Incidentally, these (spurious) AST transform errors do not stop Gradle projects from executing their various tasks, either in Eclipse or at the CLI. The Java setup in Eclipse lets you choose to ignore errors which you know are spurious. There doesn't seem to be any way of doing that with Groovy-Eclipse.

I've spent about 2 hours recreating my projects today (and learning stuff). Tomorrow I may start from scratch again, but setting the Groovy-Eclipse "workspace level" to 2.5.9 right at the start: as I say in the SO question, and as I mentioned yesterday, I find that the whole of Eclipse goes awry when I try to change that currently.

@eric-milles
Copy link
Member

eric-milles commented Mar 4, 2020

When you open a gradle script, the default is to use the Groovy editor. If you don't want to have Groovy-Eclipse try to parse and interpret the gradle script, you can right-click on the file and choose Open With > Gradle Editor. I think there is a way to make this the default for all .gradle files.

Also, if your project has the Groovy nature added to it, the Groovy builder will run along with the Java builder. Although, it likely won't have any sources to process if you only have .gradle scripts and .java sources.

@eric-milles
Copy link
Member

eric-milles commented Mar 4, 2020

Where is your logback.groovy located? If it is in a source folder, it is not unusual for Groovy-Eclipse to try and process it. The addition of spock-core includes a Groovy AST transform and Groovy-Eclipse is trying to execute it. There is an open bug about running transforms from test dependencies on main sources: #903

@Mrodent
Copy link
Author

Mrodent commented Mar 4, 2020

I just opened logback.groovy (path {project}/src/main/resources/logback.groovy) using a plain text editor. Unfortunately the nasty error mark is still there (even after a Gradle Refresh and restart of Eclipse). The mark persists both in the editor and next to the file in Project Explorer.

As I say, my app and testing code is written entirely in groovy... all these files end ".groovy", not ".gradle". I only have two .gradle files: build.gradle and settings.gradle.

Glad to see there's a bug about this - looks like you created it. Is it a big job to tackle it?

@eric-milles
Copy link
Member

I'm not sure I track the exact nature of the problem. If your project targets Groovy 2.5 then the Groovy Compiler should be set to match. I understand there is a long-running issue with compiler switching; there are several workarounds for that including removing Groovy Compiler 3.0.

That said, I did just check in a fix for "Groovy:Unexpected problem with AST transform: null" so at least the error can properly be displayed.

And no, Spock transform should not be applied to main sources. I have not had time to get around to splitting up the project class loaders for main and test dependencies.

@Mrodent
Copy link
Author

Mrodent commented Mar 5, 2020

[SOLUTION / WORKAROUND]
I have now worked out how to switch the "workspace level" Groovy compiler: it does mess up Project Explorer initially, but if you close that View and then re-open it everything seems to have got back to normal.

More importantly, switching that to 2.5.9... means that the AST Transform error has... GONE!

For the sake of completeness, could you just say how Groovy compiler 3.0 can be removed? I couldn't find a way of doing that.

@Mrodent Mrodent closed this as completed Mar 5, 2020
@eric-milles
Copy link
Member

Just for completeness, there are at least 3 known workarounds for the "Invalid Registry Object" errors (part rendering shows red Xs) #317, et. al (links below):

  1. Have the desired Groovy Compiler version be the highest version available. Ex: if you want to use Groovy Compiler 2.5, make sure you don't have Groovy Compiler 3.0 installed. If installed, you can uninstall at Help > About Eclipse Platform > Installation Details > Installed Software.

  2. Uninstall the "m2e - slf4j over logback" plug-in: Unable to switch groovy compiler version. Error in the UI (red elements) #981 (comment)

  3. Close all editors and Package/Project Explorer before exiting/restarting eclipse. Or close and reopen them after restarting.

Also, I have submitted a fix patch to eclipse platform. It is in code review and may make Eclipse 4.16: https://git.eclipse.org/r/155098

And here are bugs for this issue:

@eric-milles
Copy link
Member

With regard to your original post, can you send a screenshot of your project with logback.groovy, build.gradle and .project open so I can understand what "interfere" refers to? It sounds like you don't have a pure gradle project, but instead have Java and Groovy natures and so there is some building/compilation going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants