Groovy 文件无法在 Intellij IDEA 中编译
我有 Maven 项目,包含 java 和 groovy 测试。 在命令行maven编译中,所有测试都在运行,但是在我的IDEA项目(由“AutoImport maven项目”自动创建)中,IDEA将groovy文件复制到/target/test-classes而不编译它们。
我的gmaven插件看起来像
<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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我遇到了同样的问题,必须在 Idea 中更改以下设置:
设置->编译器->资源模式
原来是!?*.java
我把它改成了
!?.java;!?.form;!?.class;!?.groovy;!?.scala;!?.flex;!?.kt;!?.clj
如果能够将其指定到 pom 文件中会更好,但目前还没有找到方法。
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.
GMaven 插件仅用于 Maven 编译。 Idea 使用 groovy-all jar 中包含的 Groovy 编译器。为了让 Idea 掌握它,添加项目依赖项,例如:
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.:
通过删除并从头创建 IDEA 项目(ipr 文件)来解决
Solved by removing and creating from scratch IDEA project (ipr file)
请将 groovy 文件的文件夹类型更改为源根目录。相同的步骤是右键单击文件夹 ->选择选项 - '将目录设为' ->源根
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
正如上面建议的
我把它改成了
!?.java;!?.form;!?.class;!?.groovy;!?.scala;!?.flex;!?.kt;!?.clj
我的 intellij 中已经可以使用此设置。
代码仍然没有生成通过设置->编译器修复它
并检查并行编译独立模块,然后生成它
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
这与@Opal的答案类似,但与测试相关,如问题中所问:
在IDE中,转到文件->项目结构->项目设置->模块。在项目文件树中选择 src->test->groovy 目录。按 Alt+T 使 groovy 目录成为测试源根目录
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
请检查设置|编译器|资源模式。看来 *.groovy 在某种程度上适合那里,因此它被复制到输出中而不是被编译。
Please check Settings | Compiler | Resource patterns. It appears that *.groovy somehow suits there and therefore it's copied into output instead of being compiled.
您必须更改 groovy 文件的文件夹类型以使目录成为源根目录。
You have to change folder type of groovy files to make directory as source Root.