0

In a Java library project of mine I have the following Gradle task defined

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'jacoco'

...

task createPom() {
    pom {
        project {
            groupId nexusGroupId
            artifactId nexusArtifactId
            version libVersion
            organization {
                name 'Example'
                url 'https://www.example.com'
            }
            withXml { asNode().appendNode('packaging', 'jar') }
        }
    }.writeTo("build/libs/pom.xml")
}

When I build the library the following is output to the console:

Configure project : Could not find match for name 'withXml'

I am using Gradle wrapper 4.10.3.

How can I resolve the warning?

JJD
  • 50,076
  • 60
  • 203
  • 339

1 Answers1

1

Inside the builder for the project, you can only call the setters of the native POM project model.

The method withXml is a method of Gradle's MavenPom interface and can only be called after the MavenPom has been created:

task createPom() {
    pom {
        project {
            groupId 'Foo'
            artifactId 'Bar'
            version '1.0'
        }.withXml { 
            asNode().appendNode('packaging', 'jar')
        }
    }.writeTo("build/libs/pom.xml")
}
hlg
  • 1,321
  • 13
  • 29