Gradle 3.1 seems to default to maven.metadata.legacy=true

I have a project which is published to a nexus repository using the maven-publish plugin, and from there, some third party tools parse maven-metadata.xml. It works perfectly in gradle 2.12, but since updating to gradle 3.1, the format of maven-metadata.xml has changed dramatically.

I believe that it has simply started defaulting to modelVersion 1.0.0 instead of 1.1.0. Is there a way to pass arguments to maven from gradle builds, for example -Dmaven.metadata.legacy=false ? Or am I completely wrong about the problem?

Here is gradle 2.12:

<metadata modelVersion="1.1.0">
  <groupId>stuff</groupId>
  <artifactId>more-stuff</artifactId>
  <version>0.1-SNAPSHOT</version>
  <versioning>
    <snapshot>
      <timestamp>20161104.171811</timestamp>
      <buildNumber>24</buildNumber>
    </snapshot>
    <lastUpdated>20161104171811</lastUpdated>
    <snapshotVersions>
      <snapshotVersion>
        <extension>rpm</extension>
        <value>0.1-20161104.171811-24</value>
        <updated>20161104171811</updated>
      </snapshotVersion>
      <snapshotVersion>
        <extension>pom</extension>
        <value>0.1-20161104.171811-24</value>
        <updated>20161104171811</updated>
      </snapshotVersion>
    </snapshotVersions>
  </versioning>
</metadata>

And gradle 3.1:

<metadata>
  <groupId>stuff</groupId>
  <artifactId>more-stuff</artifactId>
  <version>0.9-SNAPSHOT</version>
  <versioning>
    <snapshot>
      <timestamp>20161108.140745</timestamp>
      <buildNumber>30</buildNumber>
    </snapshot>
    <lastUpdated>20161108140745</lastUpdated>
  </versioning>
</metadata>

Apart from the fact that the modelVersion and according structure changed between major versions of Gradle what exactly are you concerned about? Gradle is sticking to the official POM specification. Tools consuming the POM should know how to handle it or they are basically broken.

Currently, there’s no way to pass in flag for changing back to modelVersion 1.0.0. If you want to change the generated XML content I’d suggest you use the withXml hook.

I think you got it backwards. The NEWER version of gradle has reverted to the OLDER version of maven. modelVersion 1.1.0 is from gradle 2.12, modelVersion 1.0.0 is from gradle 3.1

EDIT: Also the withXml hook appends to the resulting pom.xml but not to the resulting maven-metadata.xml. I already tried that.

My bet. Good points, you are correct. Apart from all of these facts what’s your concern?

The tool we use for sorting our repo reads the <extension> tag since we handle rpm artifacts differently. But in the 1.0.0 specification, the entire <snapshotVersions> section is missing. Clearly gradle, and maven-publish, are aware of the file extensions. You can add artifacts using the artifact source: stuff, extension: rpm format. But the resulting metadata.xml is still missing the extension.

So I guess my point is, a newer version of gradle should not revert to an older maven specification while providing no control over the mechanism.

Thanks for the explanation. I am not quite sure why exactly we reverted back to the 1.0.0 metadata specification with Gradle 3.0. There must have been a good reason for it. If you’d like for us to look into the issue more deeper please open an issue on GitHub as explained in this blog post.