I have been trying to create a Groovy project with Spock testing in IntelliJ IDEA.
Here are steps that I followed:
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.
Add Groovy script IntelliJ IDEA opens the file in the editor. Type the following code: println("Hello, Groovy!") Press Ctrl+Shift+F10 to run the script.
The Groovy plugin is bundled with IntelliJ IDEA and enabled by default. IntelliJ IDEA supports the latest stable version of Groovy and Groovy 4 syntax.
To create a Groovy project go to File>New>Project: Select 'Groovy' in the left list. On the right panel click on 'Create...' button to select Groovy library. Now click on 'Next' button.
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>
There were two steps to fixing the (broken) project:
orderEntry type="library" exported="" scope="TEST" name="Maven: org.codehaus.groovy:groovy-all:2.2.1" level="project"
with this one:
<orderEntry type="library" name="groovy-2.2.1" level="application" />
This situation was caused by two factors: me being new to the IDE and the fact that things kinda-sorta work even when you mis-configure the project. I still think this Q&A might be useful to someone in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With