Groovy file does not compile in Intellij IDEA

旧街凉风 提交于 2019-12-04 21:29:31

问题


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>

回答1:


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.




回答2:


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>
...



回答3:


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




回答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




回答5:


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




回答6:


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




回答7:


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




回答8:


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



来源:https://stackoverflow.com/questions/8310563/groovy-file-does-not-compile-in-intellij-idea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!