title: Creating a maven wrapper pom.xml from gradle: can't create the <build> element
body: <p>How do I set the <code>sourceDirectory</code>, <code>testSourceDirectory</code> and build <code>plugins</code> in a pom.xml that I'm creating using the gradle maven-plugin's <code>pom</code> DSL?</p>
  
  <p>When I add <code>build</code> without a <code>Closure</code> to my DSL section, it's ok.. but when I add <code>build { /* anything else, like actual compile plugins */}</code> it gives me this error:</p>
  
  <pre><code>Execution failed for task ':mavenWrapper'.
  &gt; No such property: _SCRIPT_CLASS_NAME_ for class: org.apache.maven.model.Model
  </code></pre>
  
  <p>I'm guessing that gradle is treating <code>build</code> as the task rather than the DSL verb generated by <code>org.sonatype.maven.polyglot.groovy.builder.ModelBuilder</code>.</p>
  
  <p>Is there a way to force <code>build</code> to be treated as part of the DSL? Can it be cast or something?</p>
  
  <p>Right now I'm working around this by using <code>.withXml</code> but it's massively verbose and much less maintainable.</p>
  
  <p>Here's an abbreviated version of what I've got working:</p>
  
  <pre><code>task mavenWrapper {
      doLast {
          delete 'pom.xml', 'mvnw', 'mvnw.cmd'
          pom {
              project {
                  packaging 'pom'
                  repositories {
                      repository {
                          id 'spring-milestones'
                          name 'Spring Milestones'
                          url 'https://repo.spring.io/libs-milestone'
                          snapshots {
                              enabled 'false'
                          }
                      }
                  }
                  properties {
                      'kotlin.compiler.incremental' 'true'
                  }
                  /* ******** Problem is here
                  build {
                      plugins {
                          plugin {
                              // ... etc. etc.
                          }
                      }
                  }
                  ******* */
                  dependencyManagement {
                      dependencies {
                          dependency {
                              groupId 'org.jetbrains.kotlin'
                              artifactId 'kotlin-stdlib-jre8'
                              version "${kotlin_version}"
                              scope 'compile'
                          }
                      }
                  }
              }
          }.withXml {
             // Workaround for the missing build { ... } section above.
             asNode().appendNode('build').appendNode('plugins')
             // etc. etc.
          }.writeTo("${projectDir}/pom.xml")
          exec {
              commandLine 'mvn', '-N', 'io.takari:maven:wrapper', '-Dmaven=3.5.0'
          }
      }
  }
  </code></pre>