从gradle创建maven包装器pom.xml:不能创建<build>元素

我如何设置sourceDirectorytestSourceDirectory并在我使用gradle maven-plugin的pom DSL创建的pom.xml中构建plugins

当我添加没有Closure到我的DSL部分的build ,没关系..但是当我添加build { /* anything else, like actual compile plugins */}它给了我这个错误:

 Execution failed for task ':mavenWrapper'. > No such property: _SCRIPT_CLASS_NAME_ for class: org.apache.maven.model.Model 

我猜Gradle将build视为任务,而不是由org.sonatype.maven.polyglot.groovy.builder.ModelBuilder生成的DSL谓词。

有没有办法强制build被视为DSL的一部分? 它可以被施放什么?

现在我正在通过使用.withXml解决这个问题,但是它非常冗长,而且维护起来也很少。

这里是我工作的缩写版本:

 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' } } }