Published Gradle Metadata modifications

Due to implementation of a internal workaround in our dependency resolution, we need to modify the published pom file (being published with the maven-publish plugin) to adjust a dependency version. I can accomplish this in the published pom file using MavenPom.withXML():

        mvnPublication.pom.withXml { XmlProvider xml ->
          def hasDependencies = !asNode().dependencies.isEmpty()
          if (hasDependencies) {
            asNode().dependencies.first().each {
              def groupId = it.get("groupId").first().value().first()
              def version = it.get("version").first().value().first()
              if (groupId == 'testGroup' && version == 'changeVersion') {
                it.get("version").first().value = newVersion
              }
            }
          }
        }

While this appropriately changes the published pom file, the Gradle module metadata (module.json) still retains the original version. This causes an inconsistency in the published Maven pom file and Gradle module metadata.
What is the proper way to make such a change that is reflected in both the published Maven pom file and Gradle module.json file?

1 Like

Hi! Have you find the solution?

buried in the docs is MavenPublication - Gradle DSL Version 9.2.1

which refers to this api

publishing {
  publications {
    maven(MavenPublication) {
      from components.java
      versionMapping {
        usage('java-runtime'){
          fromResolutionResult()
        }
      }
    }
  }
}

you could use the above or replace with custom logic as you like

Generally, the recommendation is always to never manual fiddle with the pom or manual files, but instead fix the model / component, so that the intended result comes out, then it is also consistent among all.