Java ear with custom xml in deploymentDescriptor

While trying to configure the deploymentDescriptor within an ear. I’m trying to add custom xml, and attempted to follow the instructions customizing deploymentDescriptor.

I added the block:

ear {
  jar.enabled = false
  archiveFileName = 'service.ear'
  libDirName 'APP-INF/lib'

  deploymentDescriptor {
    version = 7
    archiveVersion = '7'
    applicationName = 'service'
    initializeInOrder = false
    displayName = 'The display name'
    description = 'Something more useful then not.'

    withXml { // add a custom node to the XML
      asElement().apply {
        appendChild(ownerDocument.createElement("data-source").apply { textContent = "my/data/source" })
      }
    }
  }

However, I get the following error:

* What went wrong:
Execution failed for task ':ear:ear'.
> No signature of method: com.sun.org.apache.xerces.internal.dom.DeferredElementImpl.apply() is applicable for argument types: (build_5w60zm26ql8m4n529b89b5p9c$_run_closure2$_closure7$_closure10$_closure12) values: [build_5w60zm26ql8m4n529b89b5p9c$_run_closure2$_closure7$_closure10$_closure12@1f3ff708]
  Possible solutions: any(), any(groovy.lang.Closure), every(), tap(groovy.lang.Closure), every(groovy.lang.Closure), split(groovy.lang.Closure)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

What am I doing wrong?

  • Mike D.

I was able to solve this by means of using this style code block:


    withXml { provider -> // add a custom node to the XML
      provider.asNode().appendNode('module_loader', 'false')
    }