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

9

39

enter image description hereI have cloned the project from github and then imported it to inetllij 2017.1. and also added all dependency modules. Basically, we are trying to upgrade our project using latest jars.

When I try to build I get the above error along with 933 errors, jdk 1.7,grails 2.5 and tomcat 8 is used. Run configuration is also throwing error as Run Configuration: cannot execute Note : previous version of my project works perfectly fine with all same settings Please help.

Mandelbaum answered 17/4, 2017 at 11:34 Comment(1)
Which project did you clone? As it stands, there's not enough info here to help...Lysozyme
S
66

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

groovy support

Slicker answered 17/4, 2017 at 11:47 Comment(8)
Thank you, It was successful in removing the first error i.e. Error:Cannot compile Groovy files: no Groovy library is defined for module “myprojectname”. But remaining 900+ errors :(Mandelbaum
Solve them one by one, it looks like some module dependencies may be missing, so start with adding them.Slicker
Yes, you are right. Issue was with Intellij 2017 new features. Thank you. Now I am dealing with new task where I have to create a scenario where the folder gets full, proper exception should be thrown. So any suggestion where I can limit the folder size where file are stored.Mandelbaum
I suggest submitting a separate question with the problem details since it's unrelated to your original question.Slicker
You need to also download the Gradle binary and attach the root of that folder in IntelliJ.Leboff
Solved my problem, had to do it for every module in my projectAntitype
@Varun the screenshot shows exactly where to click and the menu that is shown after click.Slicker
If you want to add the groovy support, but don't have it installed(like me), you can install it following the instructions here: groovy-lang.org/install.html (for mac os x) and then configure it in Intellij following bonusbits.com/wiki/HowTo:Add_Groovy_SDK_to_IntelliJ_IDEA. This helped me figure it out finally after a few hours of trying to fix it.Dragonroot
K
10

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.

Kozak answered 16/10, 2017 at 9:36 Comment(2)
Thanks. This was my problem too, having had an enum created for me that got created under the main src tree. I deleted that rogue groovy class and all good again.Straub
Similar issue here also - I had accidentally created a .groovy file in my "java" source tree! Thanks for this answerJackquelinejackrabbit
T
6

Steps to follow:

  • Go to File -> Project Structure
  • From modules add the framework support (click on the + icon) for Groovy i.e. where you have the Groovy SDK on your system:

enter image description here

Telemark answered 13/12, 2019 at 6:12 Comment(0)
C
4

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.

Cheeks answered 2/9, 2019 at 13:41 Comment(0)
E
1

In my case I have updated IntelliJ Idea CE and restarted IDE after invalidating caches. To fix this I had to do the following to refresh the gradle project in IDE:

  1. View / Tool WIndow / Gradle
  2. Select root node in tree of gradle tool window
  3. Right click and select Refresh Gradle Project
Executive answered 25/3, 2019 at 13:29 Comment(0)
C
0

I get this error when I run the project without "Create separate module per source set" option and re-import.

Crat answered 13/5, 2019 at 11:40 Comment(0)
F
0

I had similar issue when switching between projects, which were using different grails versions.

Solution: delete out and build directories and download all the dependencies once again by running grails command from console.

Florentinaflorentine answered 16/6, 2019 at 0:31 Comment(0)
I
0

Use Project Settings -> Modules -> Relevant Module -> Add -> Groovy

Indoor answered 12/8, 2021 at 12:0 Comment(0)
T
0

I had this error while trying to debug remotely .jsp files in IntelliJ Idea using JSR 45 Remote Debugger.

If it's your case, you will have to remove the default script "Build" executed at the before Launch

Empty Before Launch stack

Torrance answered 14/12, 2021 at 16:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.