Firstly, I installed the eclipse Groovy plugin, this was a piece of cake since I was only a few of steps away of it. Via the Marketplace of my Spring Tool Suite (STS): Help - Eclipse Marketplace - Search for Groovy -Install
Install Groovy plugin |
Groovy plugin for eclipse can be also found under the following URL: Groovy Plugin for Eclipse
Since, the first step was completed, I moved to the second one and I created a new Groovy class by following the path in Eclipse: File - New - Other - Groovy - Groovy Class.
New Groovy class |
My java code was already under a Maven project, so I followed the standard maven approach and placed my Groovy classes under src/main/groovy and src/test/groovy and keep my Java classes under src/main/java and src/test/java structure.
Maven Structure |
HINT: In case the Groovy folders /src/test/groovy and /scr/main/groovy are not displayed, select your project and by right clicking select Build Path - Configure Build Path - Add Folder then include the folders on your view as:
Display Groovy Folders |
Then, as a third step, I converted my project to a Groovy one by just selecting my project then by right clicking on option Configure - Convert to Groovy Project.
Convert to Groovy |
In order to achieve it, in the pom.xml, I included the dependency tag for Groovy:
<dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>${groovyVersion}</version> <dependency> </dependencies>also, i needed a Groovy plugin with the goal “generateStubs”,so included the following tags:
<plugin> <groupId>org.codehaus.gmaven</groupId> <artifactId>gmaven-plugin</artifactId> <configuration> <providerSelection>1.8</providerSelection> </configuration> <executions> <execution> <goals> <goal>generateStubs</goal> <goal>compile</goal> <goal>generateTestStubs</goal> <goal>testCompile</goal> </goals> </execution> </executions> </plugin>
The goal "generateStubs" was I a surprise for me when I realized that, as its name dedicate,creates java stubs of groovy classes.To understand it, consider a java class which needs a Groovy one to compile with and since maven standard compile process starts with /main and /test java packages and then with the /main and /test Groovy packages, compilation would stop with errors without it.