# Some elements are removed when generate a pom.xml using the maven-publish plugin

**URL:** <https://discuss.gradle.org/t/some-elements-are-removed-when-generate-a-pom-xml-using-the-maven-publish-plugin/2073>\
**Category:** Old Forum Archive\
**Created:** [April 24, 2014, 3:44am UTC](https://discuss.gradle.org/t/some-elements-are-removed-when-generate-a-pom-xml-using-the-maven-publish-plugin/2073 "2014-04-24T03:44:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaken\_Jarvis](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jaken_jarvis/32/504_2.png) [@Jaken\_Jarvis](https://discuss.gradle.org/u/Jaken_Jarvis)\
**Post date:** [April 24, 2014, 3:44am UTC](https://discuss.gradle.org/t/some-elements-are-removed-when-generate-a-pom-xml-using-the-maven-publish-plugin/2073/1 "2014-04-24T03:44:00Z")

</div>

I tried to generate a pom.xml that is similar to the Maven multi-project. Oddly enough, I noticed that “version” and “description” is not generated. I have created the build.gradle of minimum configuration, please look at this.

```gradle
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
    }
}
  ext {
    mavenRepository = "repository"
}
  project.group = "com.test"
project.version = "1.0.0"
  apply plugin: 'maven-publish'
    createPom = {
    parent {
        groupId "org.sonatype.oss"
        artifactId "oss-parent"
        version "7"
    }
      name "Test Parent"
    description "This is a test."
    url "https://test.com/"
    inceptionYear "2012"
      modules {
        module "test-library"
    }
}
  publishing {
    publications {
        maven(MavenPublication) {
            artifactId "test-parent"
              pom.withXml {
                asNode().children().last() + createPom
            }
        }
    }
    repositories {
        maven {
            url(mavenRepository)
        }
    }
}

```

The following error occurs is this.

```gradle
C:\Verify>gradle publish
Creating properties on demand (a.k.a. dynamic properties) has been deprecated an
d is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/c
urrent/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information
on the replacement for dynamic properties.
Deprecated dynamic property: "createPom" on "root project 'Verify'", value: "bui
ld_6gm9jhjtls60i9un...".
:generatePomFileForMavenPublication
:publishMavenPublicationToMavenRepository FAILED
  FAILURE: Build failed with an exception.
  * What went wrong:
Execution failed for task ':publishMavenPublicationToMavenRepository'.
> Failed to publish publication 'maven' to repository 'maven'
   > Unable to initialize POM pom-default.xml: Missing version element from pare
nt element for project com.test:test-parent
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.
  BUILD FAILED
  Total time: 7.004 secs

```

“build/publications/maven/pom-default.xml” that have been generated.

```gradle
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>test-parent</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>
  <parent>
    <groupId>org.sonatype.oss</groupId>
    <artifactId>oss-parent</artifactId>
  </parent>
  <name>Test Parent</name>
  <url>https://test.com/</url>
  <inceptionYear>2012</inceptionYear>
  <modules>
    <module>test-library</module>
  </modules>
</project>

```

gralde may not be able to interpret them, but it should be output pom.xml as intended. Thanks.

---

<div class="post-metadata">

**Author:** ![daz](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daz/32/2475_2.png) [@daz](https://discuss.gradle.org/u/daz)\
**Post date:** [April 26, 2014, 5:16pm UTC](https://discuss.gradle.org/t/some-elements-are-removed-when-generate-a-pom-xml-using-the-maven-publish-plugin/2073/2 "2014-04-26T17:16:00Z")

</div>

Seems like this has something to do with using XmlMarkupBuilder to define the pom content, where some of the element names are already in scope for the closure. There may be a groovy way to solve this, or you could build the pom using the XML Node API:

```gradle
apply plugin: 'maven-publish'
def createPom = {
    name "Test Parent"
    url "https://test.com/"
    inceptionYear "2012"
    modules {
        module "test-library"
    }
}
publishing {
    publications {
        maven(MavenPublication) {
            artifactId "test-parent"
            pom.withXml {
                asNode().appendNode("description", "This is a test.")
                def parent = asNode().appendNode("parent")
                parent.appendNode("groupId", "org.sonatype.oss")
                parent.appendNode("artifactId", "oss-parent")
                parent.appendNode("version", "7")
                asNode().children().last() + createPom
            }
        }
    }

```

---

<div class="post-metadata">

**Author:** ![daz](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daz/32/2475_2.png) [@daz](https://discuss.gradle.org/u/daz)\
**Post date:** [April 26, 2014, 5:18pm UTC](https://discuss.gradle.org/t/some-elements-are-removed-when-generate-a-pom-xml-using-the-maven-publish-plugin/2073/3 "2014-04-26T17:18:00Z")

</div>

Just tested and this also seems to work by telling the XML Closure to resolve DELEGATE\_ONLY:

```gradle
def createPom = {
    parent {
        groupId "org.sonatype.oss"
        artifactId "oss-parent"
        version "7"
    }
    name "Test Parent"
    description "This is a test."
    url "https://test.com/"
    inceptionYear "2012"
    modules {
        module "test-library"
    }
}
createPom.resolveStrategy = Closure.DELEGATE_ONLY

```

---

<div class="post-metadata">

**Author:** ![Jaken\_Jarvis](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jaken_jarvis/32/504_2.png) [@Jaken\_Jarvis](https://discuss.gradle.org/u/Jaken_Jarvis)\
**Post date:** [April 27, 2014, 8:36am UTC](https://discuss.gradle.org/t/some-elements-are-removed-when-generate-a-pom-xml-using-the-maven-publish-plugin/2073/4 "2014-04-27T08:36:00Z")

</div>

Oops, It was my mistake? I think that when added to documents, it is very helpful. [http://www.gradle.org/docs/current/userguide/publishing\_maven.html](http://www.gradle.org/docs/current/userguide/publishing_maven.html)

Hmm, however, I do not understand why it works. Apparently, my knowledge about the closure is will not be enough… Thank you anyway.

---

<div class="post-metadata">

**Author:** ![daz](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daz/32/2475_2.png) [@daz](https://discuss.gradle.org/u/daz)\
**Post date:** [April 28, 2014, 11:48pm UTC](https://discuss.gradle.org/t/some-elements-are-removed-when-generate-a-pom-xml-using-the-maven-publish-plugin/2073/5 "2014-04-28T23:48:00Z")

</div>

It’s confusing, I know…

I’m guessing that the XML builder is using methodMissing to generate the xml from the closure. But since there is already a ‘version’ and ‘description’ in the scope of the closure (on the containing ‘project’ instance), these are not ‘missing’ so the XML elements are not generated. By telling the closure only to resolve against the delegate, and not the _owner_ of the closure, the ‘version’ and ‘description’ are no longer in scope.

---

<div class="post-metadata">

**Author:** ![Jaken\_Jarvis](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jaken_jarvis/32/504_2.png) [@Jaken\_Jarvis](https://discuss.gradle.org/u/Jaken_Jarvis)\
**Post date:** [May 3, 2014, 4:54am UTC](https://discuss.gradle.org/t/some-elements-are-removed-when-generate-a-pom-xml-using-the-maven-publish-plugin/2073/6 "2014-05-03T04:54:00Z")

</div>

Hi Daz DeBoer I see, I was able to understand it in your favor 😃 Thank you!
