title: running grails 2.1.3 tests in Intellij Idea: Bizarre error in Spock test: Cannot add Domain class [class x.y.Z]. It is not a Domain
body: <p>I am in the process of upgrading to grails 2.1.x, and need to redo some of my old-style tests.</p>
  
  <p>I just added a new test to my spock Spec, and for this test I need to mock an additional Domain class.</p>
  
  <p>Before this, I had:</p>
  
  <pre><code>@Mock([Event, EventType])
  </code></pre>
  
  <p>Now I have:</p>
  
  <pre><code>@Mock([Event, EventType, Notification])
  </code></pre>
  
  <p>Notification.groovy is in the same exact package and physical directory than Event and EventType (under grails-app/domain) so it definitely is a grails domain class.</p>
  
  <p>When I try to run my test I get the following stack trace:</p>
  
  <pre><code>org.codehaus.groovy.grails.exceptions.GrailsConfigurationException: Cannot add Domain class [class x.y.Notification]. It is not a Domain!
      at org.codehaus.groovy.grails.commons.DefaultGrailsApplication.addArtefact(DefaultGrailsApplication.java:911)
      at org.codehaus.groovy.grails.commons.DefaultGrailsApplication.addArtefact(DefaultGrailsApplication.java:615)
      at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomain(DomainClassUnitTestMixin.groovy:131)
      at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomain(DomainClassUnitTestMixin.groovy:128)
  </code></pre>
  
  <p>When I go through the rabbit hole and start debugging the execution, I get to this portion of DomainClassArtefactHandler (line 87):</p>
  
  <pre><code>            // make sure the identify and version field exist
              testClass.getDeclaredField(GrailsDomainClassProperty.IDENTITY);
              testClass.getDeclaredField(GrailsDomainClassProperty.VERSION);
  </code></pre>
  
  <p>this blows up with an exception, because I guess the id field is not present</p>
  
  <p>So something is going wrong, the GORM fields are not added before this is executed.</p>
  
  <p>Does anyone have a suggestion of what I need to do? Do I need to mark my domain class as an @Entity (this actually makes my test pass)?</p>
  
  <p>I am pretty sure that's not supposed to be mandatory for my unit test to pass.</p>
  
  <p>Any advice?</p>
  
  <p><strong>UPDATE:</strong>
  Actually, I have just discovered that this issue only arises when I run the unit tests inside my IDE: intellij Idea 12.1</p>
  
  <p>Issues created, with test app here:</p>
  
  <p><a href="http://jira.grails.org/browse/GRAILS-9989" rel="noreferrer">http://jira.grails.org/browse/GRAILS-9989</a></p>
  
  <p><a href="http://youtrack.jetbrains.com/issue/IDEA-105087" rel="noreferrer">http://youtrack.jetbrains.com/issue/IDEA-105087</a></p>
  
  <p>When I remove the static mapping blocks in both domain classes, the test passes!</p>