Groovy file does not compile in Intellij IDEA
Solution 1
Solved by removing and creating from scratch IDEA project (ipr file)
Solution 2
I had the same issue and had to change in Idea the following setting: Settings->Compiler->Resource patterns
It was !?*.java
I changed it into !?.java;!?.form;!?.class;!?.groovy;!?.scala;!?.flex;!?.kt;!?.clj
It would be better to be able to specify it into the pom file though but haven't found a way yet.
Solution 3
GMaven plugin is only intended for maven compilation. Idea uses the Groovy compiler included in groovy-all jar. For Idea to get a hold of that add a project dependency, e.g.:
...
<groupId>yourproject</groupId>
<artifactId>yourproject</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>
</dependencies>
...
Solution 4
Please change folder type of groovy files as Source Root. Step for same is Right Click on folder -> Select option - 'Make Directory as' -> Source Root
Pavel Bernshtam
Java Programmer since 1996 Was born in Ukraine, live in Israel since 1994 Java/Scala/Groovy
Updated on September 04, 2020Comments
-
Pavel Bernshtam almost 4 years
I have maven project wit java and groovy tests. In command line maven compilation all tests are running, but in my IDEA project (which is created automatically, by "AutoImport maven projects", IDEA copies groovy files to /target/test-classes without compiling them.
My gmaven plugin looks like
<plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>gmaven-plugin</artifactId> <version>1.3</version> <executions> <execution> <goals> <goal>generateStubs</goal> <goal>compile</goal> <goal>generateTestStubs</goal> <goal>testCompile</goal> </goals> <configuration> <providerSelection>1.7</providerSelection> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>${groovy.version}</version> </dependency> </dependencies> </plugin>
-
Pavel Bernshtam over 12 yearsYes, I have such dependency. I even see it in IDEA module dependencies
-
Nikita Volkov over 12 yearsTry to go to ''Project Structure/Facets'' and set up the appropriate compiler for your module there. It should be in a drop down list of jars.
-
Pavel Bernshtam over 12 yearsI do not see "Groovy" in the list of Facets. What may be a reason?
-
Nikita Volkov over 12 yearsIgnore my comment about "Project Structure/Facets", it's not applicable to Groovy, sorry. 1. Check out whether your groovy sources are stored at /src/main/groovy or /src/test/groovy 2. Check out your run/debug configurations. The ''Make'' option must be checked 3. Try deleting Idea files and reimporting your POM 4. Try upgrading Idea to latest EAP
-
Pavel Bernshtam over 12 years1. Yes, I have tests in src/test/groovy 2. Yes, I make or compile separate class individually I even created groovy as global library and added it to the module instead of Maven dependency - it does not help :(
-
Pavel Bernshtam over 12 yearsI have a module, where groovy compiles ok, but If I add this module to the existing project, it does not work
-
jblack about 10 yearsChanging my dependency from groovy to groovy-all fixed it for me.
-
Ashwani Agarwal over 2 yearswhat is the location of this file? (10 years and still feels relevant)