Groovy file does not compile in Intellij IDEA
Asked Answered
B

8

8

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>
Bosporus answered 29/11, 2011 at 12:18 Comment(0)
B
5

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

Bosporus answered 1/12, 2011 at 11:16 Comment(1)
what is the location of this file? (10 years and still feels relevant)Epistemology
G
7

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.

Geddes answered 5/2, 2013 at 3:17 Comment(0)
L
5

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>
...
Linnealinnean answered 29/11, 2011 at 12:46 Comment(6)
Yes, I have such dependency. I even see it in IDEA module dependenciesBosporus
Try 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.Linnealinnean
I do not see "Groovy" in the list of Facets. What may be a reason?Bosporus
Ignore 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 EAPLinnealinnean
1. 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 :(Bosporus
Changing my dependency from groovy to groovy-all fixed it for me.Caudate
B
5

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

Bosporus answered 1/12, 2011 at 11:16 Comment(1)
what is the location of this file? (10 years and still feels relevant)Epistemology
A
1

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

Amaze answered 14/4, 2015 at 7:41 Comment(0)
M
0

As suggested above I changed it into !?.java;!?.form;!?.class;!?.groovy;!?.scala;!?.flex;!?.kt;!?.clj This setting was already available in my intellij. Still the code was not generating Fixed it by Setting->Compiler and check compile independent module in parallel and after that it got generated

Mudslinging answered 5/4, 2018 at 6:27 Comment(0)
S
0

This is similar to @Opal's answer, but is relevant for tests, as asked in the question:

In the IDE go to Files->Project Structure->Project Settings->Modules. In the Project files tree select the src->test->groovy directory. Hit Alt+T to make the groovy directory the test source root

Seurat answered 3/9, 2019 at 11:8 Comment(0)
N
-1

Please check Settings | Compiler | Resource patterns. It appears that *.groovy somehow suits there and therefore it's copied into output instead of being compiled.

Nabataean answered 29/11, 2011 at 19:27 Comment(1)
I have a module, where groovy compiles ok, but If I add this module to the existing project, it does not workBosporus
C
-2

You have to change folder type of groovy files to make directory as source Root.

Carnassial answered 14/4, 2015 at 7:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.