2

So I know how to generate a pom file using the maven plugin in gradle, as described here.

Now I want to include a properties section to the generated pom, for example like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycorp.mycomponent</groupId>
  <artifactId>mything/artifactId>
  <version>myversion</version>
  <packaging>zip</packaging>
  <properties>
    <bom_status>SUCCESS</bom_status>
    <bom_url>http://jenkins/job/build-mything/9735/</bom_url>
    <bom_md5sum>ac69702b40cd3f68cd76a1a2d59ae08d</bom_md5sum>
    <bom_sha1sum>b4cf32524b42a7bf0b8cdba8a383624525bd7727</bom_sha1sum>
  </properties>
</project>

How would I do that?

Community
  • 1
  • 1
Christian Goetze
  • 2,254
  • 3
  • 34
  • 51

1 Answers1

3

Same as you generated the POM itself.

Once you generated the pom object, you can do:

def updatePomWithProperties(pomObject) {
    pomObject.project {
        properties {
            bom_status = "SUCCESS"
            bom_url = "http://jenkins/job/build-mything/9735/"
            bom_md5sum = "ac69702b40cd3f68cd76a1a2d59ae08d"
            bom_sha1sum = "b4cf32524b42a7bf0b8cdba8a383624525bd7727"
        }
    }
}
yonisha
  • 2,956
  • 2
  • 25
  • 32
  • Strange... I got to `properties {...}`, but then I never know when to put in an assignment vs a function call. Also, it's interesting that I have to first generate the object, then apply the change. I tried doing it in one swoop, and that gets me a bizarre "location" error. – Christian Goetze Jul 29 '16 at 16:43