IntelliJ + Groovy + Spock

Daniil Shevelev picture Daniil Shevelev · Jan 27, 2014 · Viewed 22.6k times · Source

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.

Answer

MariuszS picture MariuszS · Jan 27, 2014

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

groovy source code

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>