How to elegantly customize the pom.xml using the new publishing plugin


(Etienne Studer) #1

Hi

Is there a more elegant (Groovy) way than repeatedly calling appendNode() to customize the pom.xml?

publishing {
    publications {
        mavenJava(MavenPublication) {
         from components.java
           pom.withXml {
                asNode().appendNode('name', 'some name')
                asNode().appendNode('description', 'some description')
                asNode().appendNode('developers').appendNode('developer').
                        appendNode('id', 'someid').parent().
                        appendNode('name', 'somename').parent().
                        appendNode('email', 'someemail')
                  asNode().appendNode('licenses').appendNode('license').
                        appendNode('name', 'Apache License, Version 2.0').parent().
                        appendNode('url', 'http://www.apache.org/licenses/LICENSE-2.0.html')
            }
        }
    }
    ....
}

#2

Not sure if I’d call it ‘elegant’, but you can use ‘Node.plus()’ to append content using the Groovy XmlMarkupBuilder.

See this forum post for more details: http://forums.gradle.org/gradle/topics/new_publishing_model_and_pom_customization_via_xmlprovider


(Etienne Studer) #3

This is definitely more elegant than what I had before. Thanks, Daz.


(Justin Ryan) #4

This is good stuff to put into a plugin. We put most of the updating of the pom into the nebula-publishing-plugin, and the developers section into the gradle-contacts-plugin. I’m still looking to put the license bits and the scm bits into appropriate plugins.