Reputation: 535
I'm attempting a Hello World in Groovy using Intellij. I'm using the latest Intellij:
I installed Groovy using sdkman:
When I create a new Groovy project it recognizes that I have Groovy installed
When I create a groovy file in the src
directory and try to run it
I get the error Error:Cannot compile Groovy files: no Groovy library is defined for module 'new-groovy'
So then I check my module in Project Structure and groovy does show up in the dependencies (this is where my case differs from the previously accepted answer to this error)
Groovy is also listed as a library (I don't know why PHP is listed as a library for every single new project)
I tried different combinations of changing the value in the dropdown from compile to the other options, checking and unchecking the Export option. In watching online demonstrations of the above steps I can't see anything different in my setup.
Upvotes: 3
Views: 11273
Reputation: 535
The only thing that worked was deleting all of my Intellij/Jetbrains global config files. I went into ~/Library/Preferences
and deleted anything that had Jetbrains or Intellij in its filename. I have been reusing the config files for the past two years across several versions. It caught up with me. Groovy files will compile now.
Upvotes: 3
Reputation: 4482
I don't really have a direct solution to your problem, but can perhaps provide a couple of things to check.
I created a sample project from the Groovy template in IntelliJ 2017.3 (what I have, hopefully not the reason for the difference). I then added a HelloWorld class and hit the "Run 'Hello World'" play button in the intellij toolbar with the results as per screen below.
One thing worth checking is your run configuration (Main Menu -> Run -> Edit Configurations...
) and that you have your main module new-groovy
selected in the "Use classpath of module" dropdown.
Also if you expand the groovy node in your project view (your last screen), does IntelliJ point at files that actually exist on disk? Reason I ask is sometimes you make changes via sdkman and leave a previously valid sdk registration in IntelliJ dangling and invalid.
Upvotes: 1