Groovy file does not compile in Intellij IDEA

I have maven project wit java and groovy tests. On the Maven compilation command line, all tests work, but in my IDEA project (which is created automatically, "AutoImport Maven projects", copies IDEA 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> 
+8
source share
8 answers

Solved by deleting and creating from scratch the IDEA project (ipr file)

+5
source

I had the same problem and I had to change the following setting in Idea: Settings-> Compiler-> Resource Templates

It was !? *. java

I changed it to!?. Java;!?. The form;!?. Class;!?. Clockwork;!?. Scala;!?. Bend;!?. Kt;!?. CLJ

It would be better to specify it in the pom file, but have not yet found the path.

+7
source

The GMaven plugin is for maven compilation only. Idea uses the Groovy compiler included in the groovy -all jar. So that the idea can hold this, add a project dependency, for example:

 ... <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> ... 
+5
source

Change the groovy folder type as the source root. The step for this is Right. Click on the folder → Choose option - “Make directory as” → Source root

+1
source

As suggested above, I changed this to!?. Java;!?. The form;!?. Class;!?. Clockwork;!?. Rock;!?. Bend;!?. Kt;!?. CLJ This option was already available in my intellij. The code was still not generated. Fixed Setting-> Compiler. and check the compilation of the independent module in parallel and after that it was generated

0
source

This is similar to @Opal's answer, but applies to tests as stated in the question:

In the IDE, go to Files-> Structure project-> Project Settings-> Modules. In the project file tree, select the src-> test-> groovy directory. Press Alt + T to turn the groovy directory into the root directory of the tests.

0
source

Check settings | Compiler | Resource Models. It seems that * .groovy is somehow suitable and therefore is copied to the output file instead of compiling.

-1
source

You need to change the type of the groovy folder to make the directory the source of Root.

-2
source

Source: https://habr.com/ru/post/902642/