IntelliJ + Groovy + Spock [英] IntelliJ + Groovy + Spock

查看:134
本文介绍了IntelliJ + Groovy + Spock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



以下是我遵循的步骤:


  1. 创建了Groovy项目并添加了Maven支持。
  2. 添加了Spock依赖项和插件。我使用的POM与此类似:
    https:// github.com/mariuszs/java-spock-test-sample/blob/master/pom.xml 由于Groovy依赖冲突,我从模块设置中删除了Groovy 2.2库 - >库。这允许我运行测试。

  3. 我在src / main创建了一个Groovy类,但是当我尝试运行它时遇到错误:

Groovyc:无法编译Groovy文件:没有为模块定义Groovy库...



我可能错过了一些东西,因为我厌倦了在一天的时间里尝试不同的配置。

div>

对于完全groovy项目尝试 GMavenPlus



示例项目: https://github.com/mariuszs/groovy-maven -sample



安装 GMavenPlus IntelliJ Plugin
IntelliJ不识别源目录 src / main / groovy ,如下所示从项目设置 - >模块窗口手动配置。





配置

 < project> 
< build>
< plugins>
< plugin>
< groupId> org.codehaus.gmavenplus< / groupId>
< artifactId> gmavenplus-plugin< / artifactId>
< version> 1.5< / version>
<执行次数>
<执行>
<目标>
< goal>编译< / goal>
< goal> testCompile< / goal>
< /目标>
< /执行>
< /执行次数>
< / plugin>
< / plugins>
< / build>
<依赖关系>
< dependency>
< groupId> org.codehaus.groovy< / groupId>
< artifactId> groovy-all< / artifactId>
< version> 2.4.4< / version>
< /依赖关系>
< dependency>
< groupId> org.spockframework< / groupId>
< artifactId> spock-core< / artifactId>
< version> 1.0-groovy-2.4< / version>
< scope> test< / scope>
< /依赖关系>
< /依赖关系>
< / project>


I have been trying to create a Groovy project with Spock testing in IntelliJ IDEA.

Here are steps that I followed:

  1. Created Groovy project and added Maven support.
  2. Added Spock dependencies and plugin. I am using POM very similar to this one: https://github.com/mariuszs/java-spock-test-sample/blob/master/pom.xml
  3. Due to conflicting Groovy dependency I removed Groovy 2.2 library from the Module Settings->Libraries. This allowed me to run tests.
  4. I created a Groovy class in "src/main".. but I get the error when I try to run it:

Groovyc: Cannot compile Groovy files: no Groovy library is defined for module...

I am probably missing something because I am tired of trying different configurations for half of the day.

解决方案

For fully groovy project try GMavenPlus

Sample project: https://github.com/mariuszs/groovy-maven-sample

Install GMavenPlus IntelliJ Plugin. IntelliJ dont recognize source directories src/main/groovy, configure this manually as shown below from Project Settings -> Modules window:.

Configuration

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <version>1.5</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>2.4.4</version>
    </dependency>
    <dependency>
        <groupId>org.spockframework</groupId>
        <artifactId>spock-core</artifactId>
        <version>1.0-groovy-2.4</version>
        <scope>test</scope>
    </dependency>     
  </dependencies>
</project>

这篇关于IntelliJ + Groovy + Spock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆