Maven metadata with classifiers fails to resolve for snapshots

Gradle Version: 3.1 and 2.x versions
OS: Any

This happens if your project has a dependency to a SNAPSHOT who has classifiers. For some reason the maven-metadata.xml for those kind of dependencies can end up looking like this:

<metadata modelVersion="1.1.0">
    <groupId>com</groupId>
    <artifactId>mylib</artifactId>
    <version>1.0-SNAPSHOT</version>
    <versioning>
        <snapshot>
            <timestamp>20161019.072702</timestamp>
            <buildNumber>2</buildNumber>
        </snapshot>
        <lastUpdated>20161019072702</lastUpdated>
        <snapshotVersions>
            <snapshotVersion>
                <classifier>tests</classifier>
                <extension>jar</extension>
                <value>1.0-20161019.072653-1</value>
                <updated>20161019072702</updated>
            </snapshotVersion>
            <snapshotVersion>
                <extension>jar</extension>
                <value>1.0-20161019.072653-1</value>
                <updated>20161019072653</updated>
            </snapshotVersion>
        </snapshotVersions>
    </versioning>
</metadata>

The keen eye can notice here that timestamp and buildnumber is not the same in as in . The maven-metadata.xml is created by a maven project and pushed to Nexus. I do not know maven-metadata.xml ends up like this, but I does so every time. Maven it self is able to overcome this and just downloads whatever is inside

Gradle on the other hand fails with this:

> Could not find com:mylib:1.0-SNAPSHOT.
  Searched in the following locations:
      file:/gradle-maven-metadata-bug/mavenrepo/com/mylib/1.0-SNAPSHOT/maven-metadata.xml
      file:/gradle-maven-metadata-bug/mavenrepo/com/mylib/1.0-SNAPSHOT/mylib-1.0-20161019.072702-2.pom
      file:/gradle-maven-metadata-bug/mavenrepo/com/mylib/1.0-SNAPSHOT/mylib-1.0-20161019.072702-2.jar

See also how it tries to download timestamp-buildnumber.
I’ve created a reproducable project which generates this error:

A more correct way to resolve the classifier-dependency would be to use instead of resolving the url from timestamp and buildnumber.