IntelliJ + Groovy + Spock

Dan*_*lev 7 groovy intellij-idea maven spock

我一直在尝试使用IntelliJ IDEA中的Spock测试创建一个Groovy项目.

以下是我遵循的步骤:

  1. 创建了Groovy项目并添加了Maven支持.
  2. 添加了Spock依赖项和插件.我使用的POM非常类似于这个:https: //github.com/mariuszs/java-spock-test-sample/blob/master/pom.xml
  3. 由于Groovy依赖性冲突,我从Module Settings-> Libraries中删除了Groovy 2.2库.这让我可以进行测试.
  4. 我在"src/main"中创建了一个Groovy类..但是当我尝试运行它时出现错误:

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

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

Mar*_*szS 13

对于完全groovy项目尝试GMavenPlus

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

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

常规源代码

组态

<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>
Run Code Online (Sandbox Code Playgroud)

  • +1无法理解IntelliJ为何如此困难和不直观; 3个小时只是为了使用java项目进行groovy spock测试!:-D (2认同)