New publishing model and POM customization via XmlProvider

I am just upgrading Hibernate to use Gradle 1.5 and really wanted to make use of the new publishing model. I asked an earlier question already about the new model wrt multi-project builds. But I am finding it confusing in general to use this new model to customize the generated POM. Our old build did quite a bit of customization of the POM, thought mostly it is “standardly supplied info” IMO. Our old script used a closure as such:

def pomConfig = {
            organization {
                name 'Hibernate.org'
                url 'http://hibernate.org'
            }
            issueManagement {
                system 'jira'
                url 'http://opensource.atlassian.com/projects/hibernate/browse/HHH'
            }
            scm {
                url "http://github.com/hibernate/hibernate-core"
                connection "scm:git:http://github.com/hibernate/hibernate-core.git"
                developerConnection "scm:git:git@github.com:hibernate/hibernate-core.git"
            }
            licenses {
                license {
                    name 'GNU Lesser General Public License'
                    url 'http://www.gnu.org/licenses/lgpl-2.1.html'
                    comments 'See discussion at http://hibernate.org/license for more details.'
                    distribution 'repo'
                }
            }
            developers {
                developer {
                    id 'hibernate-team'
                    name 'The Hibernate Development Team'
                    organization 'Hibernate.org'
                    organizationUrl 'http://hibernate.org'
                }
            }
        }

and used that closure to configure the deployer for the upload and install task(s).

I have no clue how to accomplish this using this XmlProvider API. Granted this is likely more of a Groovy question (building node trees with groovy.util.Node class), but the again I am not a Groovy developer :slight_smile:

Any pointers? Even RTFM replies are great…with links to said manuals :stuck_out_tongue:

I see Groovy has this wonderful MarkupBuilder class. But as far as I can tell there is no way to bridge between Node or Element and MarkupBuilder.

Too bad there is no pom.withXml{ asMarkupBuilder() } option.

Any suggestions?

In the ‘old-style’ publishing DSL, the closure-based POM configuration you’re using is actually configuring the Maven Model object directly, rather than post-configuring the XML.

There’s no reason why we couldn’t provide a similar feature in the new publishing plugins, but at the moment it’s not there.

Groovy ‘MarkupBuilder’ is not really designed for editing existing documents; what’s really needed is a way to create and append nodes using the builder syntax. I started to write a post explaining how there didn’t seem to be a convenient way to do this, but then I stumbled upon a pretty good solution, using Node.plus().

The follow should work with your existing ‘pomConfig’ closure.

publishing {
  publications {
    maven(MavenPublication) {
      pom.withXml {
        asNode().children().last() + pomConfig
      }
    }
  }
}

Anybody know how to add dependences to pom with “maven publish” plugin .

Somebody add dependence manually ,pls refer to https://github.com/jeremytowne/gradle-dependency-test/blob/c902c91dbfc7197d073d00401991fdb20a8e79d7/a/a.gradle

I can do it by wrtiteNewPom with “maven” plugin ,but “maven” plugin couldn’t customize pom such as “build,plugin…" , so I try to use “maven publish” plugin to do all of thing .