title: GRAILS: groovy.lang.MissingPropertyException: No such property.
body: <p>I'm trying to debug a Grails application. Unfortunately, I have no prior experience in said language.</p>
  
  <p>When I do <strong>grails generate-all org.example.Book</strong>, I get back a vague error:</p>
  
  <pre><code>Generating controller for domain class org.example.Book ...
  groovy.lang.MissingPropertyException: No such property: Event for class: SimpleTemplateScript6
      at SimpleTemplateScript6.run(SimpleTemplateScript6.groovy:22)
      at _GrailsGenerate_groovy.generateForDomainClass(_GrailsGenerate_groovy:88)
      at _GrailsGenerate_groovy$_run_closure1.doCall(_GrailsGenerate_groovy:48)
      at GenerateAll$_run_closure1.doCall(GenerateAll.groovy:42)
      at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
      at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
      at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
      at gant.Gant.withBuildListeners(Gant.groovy:427)
      at gant.Gant.this$2$withBuildListeners(Gant.groovy)
      at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
      at gant.Gant.dispatch(Gant.groovy:415)
      at gant.Gant.this$2$dispatch(Gant.groovy)
      at gant.Gant.invokeMethod(Gant.groovy)
      at gant.Gant.executeTargets(Gant.groovy:590)
      at gant.Gant.executeTargets(Gant.groovy:589)
  Error running generate-all: No such property: Event for class: SimpleTemplateScript6
  </code></pre>
  
  <p>After looking at the generated org.example.BookController.groovy source, I noticed that it was not fully generated (stopped at List fields = []):</p>
  
  <pre><code>package org.example
  
  // import needed for export plugin
  import org.codehaus.groovy.grails.commons.ConfigurationHolder
  
  class BookController {
  
      ...
      def exportService
  
      def export = {attrs -&gt;
      def response = attrs.response
      List fields = []
  </code></pre>
  
  <p>This error <em>appears</em> to be caused by the following code in templates/scaffolding/Controller.groovy:</p>
  
  <pre><code>&lt;%=packageName ? "package ${packageName}\n\n" : ''%&gt;
  
  // import needed for export plugin
  import org.codehaus.groovy.grails.commons.ConfigurationHolder
  
  class ${className}Controller {
  
      static allowedMethods = [save: "POST", update: "POST", delete: "POST"]^M
  
      def exportService
  
      ...
  
      def export = {attrs -&gt;
      def response = attrs.response
      List fields = []
      &lt;% excludedProps = Event.allEvents.toList() &lt;&lt; 'version'
         allowedNames = domainClass.persistentProperties*.name &lt;&lt; 'id' &lt;&lt; 'dateCreated' &lt;&lt; 'lastUpdated'
         props = domainClass.properties.findAll { allowedNames.contains(it.name) &amp;&amp; !excludedProps.contains(it.name) &amp;&amp; !Collection.isAssignableFrom(it.type) }
         Collections.sort(props, comparator.constructors[0].newInstance([domainClass] as Object[]))
         props.eachWithIndex {p, i -&gt; %&gt;fields.push("${p.name}"&lt;%="\n"%&gt;&lt;% } %&gt;
         Map labels = [:]
         &lt;% props.eachWithIndex { p, i -&gt; %&gt;labels.putAt("\${p.name}", "\${p.naturalName}")&lt;%="\n "%&gt;&lt;% } %&gt;
  
         Map formatters = [:]
         Map parameters = [:]
         response.setHeader("Content-disposition", "attachment; filename=${domainClass.propertyName}s.\${attrs.extension}")
         if("\${attrs.extension}" == "xml") {
              exportService.export(attrs.format, response.outputStream, attrs.exportList, fields, [:], formatters, parameters)
         } else {
              exportService.export(attrs.format, response.outputStream, attrs.exportList, fields, labels, formatters, parameters)
         }
      }
  ...
  }
  </code></pre>
  
  <p>It appears that the def export {} block seems to be causing problems. Is there something wrong with the above code?</p>