Posterous theme by Cory Watilo

Filed under: Spock

How to fix some annoying errors that pop up when using the Grails Spock plugin with Eclipse

I've recently switched my Grails development environment from NetBeans to Eclipse (specifically, SpringSource Tool Suite), and I have to say, I'm really impressed.  With the work the guys at SpringSource have been putting into the Grails plugin recently, I can now say without a doubt that STS is now my favourite environment for Groovy/Grails development.
For example, if you're using the new dependency DSL (in BuildConfig.groovy) in Grails 1.2.x, you'll know that NetBeans doesn't add these dependencies to the project classpath, meaning red error squiggles everywhere.  On the other hand, in STS you simply have to tell your project to refresh its dependencies, and everything from BuildConfig.groovy is added to the project classpath.
As great as the Grails support in STS is, I find it to be a little over-zealous in identifying "errors" in your project.  For example, if you use the excellent Spock testing plugin, STS throws up a few obscure errors.  Here they are:

  1. An error complaining that org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter is not in the classpath will pop up against a random source file.  Fix this by adding a dependency on org.apache.ant:ant-junit:1.7.1.
  2. Your specification test classes will have Hierarchy of the type XYZ is inconsistent errors against the class definitions (classes that extend UnitSpec).  Fix this by adding a dependency on org.spockframework:spock-core:0.4-SNAPSHOT.
  3. You may also get the error The type CookieManager is ambiguous at the getCookieManager() declaration in spock/functional/WebSession.groovy.  Fix this by adding an import to CookieManager to the top of the file: import com.gargoylesoftware.htmlunit.CookieManager

You can add the two dependencies to your BuildConfig.groovy with the following statement inside the dependencies closure: compile 'org.apache.ant:ant-junit:1.7.', 'org.spockframework:spock-core:0.4-SNAPSHOT'

Now, after you refresh your project dependencies (Grails Tools -> Refresh Dependencies), these errors will disappear.