在 Intellij 中配置 groovy SDK:每次构建项目时都必须重复这个吗?

Configuring groovy SDK within Intellij: have to repeat this each time project is built?

我在 Intellij:

中尝试编译我的应用程序时遇到错误

Error:Cannot compile Groovy files: no Groovy library is defined for module

我在 Inteli 提示时通过为模块选择 "Configure Groovy SDK" 解决了这个问题。我使用了库 org.codehaus.groovy:groovy-all:2.4.4 ,然后将此库添加为模块的 dependency

问题是每次我 重新构建 我的项目或在 Intellij 中 "refresh gradle projects" 我必须 "Configure Groovy SDK" 再次。

我如何设置我的项目,这样我就不必每次都重新做这一步?

添加 groovy-all 作为您的 pom.xml(如果您使用的是 Maven)或 build.gradle(对于 gradle)的依赖项。否则每次刷新或同步时,intellij 都会删除它找到的 "extra" 依赖项。

<dependency>
    <groupId>org.codehaus.groovy</groupId>
    <artifactId>groovy-all</artifactId>
    <version>2.4.6</version>
</dependency>