Error:Cannot compile Groovy files: no Groovy library is defined for module "myprojectname"

Right click on the problematic module and add Groovy support to it:

groovy support


In my case it was a Spec placed in the src/main/java instead of the src/test/groovy. Unfortunately InteliJ doesn't present the error in that class but instead doesn't compile the whole module.

To find out which class is wrong just open the not compiled module settings ( F4 on it in Project tree) -> Dependencies (Tab) -> Groovy -> change from Test to Compile.

What makes the problem even worse is that maven compiled everything without problems.


I wrote this answer also here: Could not find org.codehaus.groovy:groovy-all:2.4.12 Similar problem here, everything was correctly installed but not found; I also refreshed everything that was refreshable in IntelliJ as reported by users who answered this and similar questions; I removed all the temporary folders in the project. Everything useless.

Then I solved the problem from terminal, running the following:

gradlew build --refresh-dependencies

This solved the issue.

In extremis (it was not necessary in my case), you can delete the content of the global cache folder used by gradle; often it's in the user's folder:

C:\Users\USERNAME\.gradle\caches

Mi esperas, ke tio helpos iun, ĉar mi perdis multe da tempo.