shields icon indicating copy to clipboard operation
shields copied to clipboard

Badge Shows Incorrect Snapshot Version on Nexus 3 Repositories

Open magicmq opened this issue 4 years ago • 7 comments

Are you experiencing an issue with...

:beetle: Description

Submitting this issue as per @PyvesB's request on Discord.

The badge below is a badge for one of my personal projects hosted on my Sonatype OSS snapshots repository. My repository is running OSS 3.28.0-1. The badge appears to show an incorrect timestamped version string for snapshot versions. The badge should show something along the lines of 0.<number>.0-SNAPSHOT (because I am actively working on this project, I cannot tell you exactly what version number you should see). Release versions on my releases repository show the correct version string on the badge. I did some troubleshooting on my own, and found that appending a ?nexusVersion=3 query parameter does not seem to help. I also found that this query returns a version consistent with the one on the badge, so my Nexus server seems to be returning results consistent with what is being shown.

Maven deploys snapshot artifacts with a timestamp so that successive artifacts can be appropriately tracked and stored (without replacing older ones). Regardless, the version that Nexus shows should not be these timestamped versions, but rather the actual version string (0.<number>.0-SNAPSHOT in my case).

I initially suspected this was a Nexus 3 issue because I troubleshooted with another Nexus 3 repository (not my own) and, like my own repository, snapshot versions were not showing the correct version string. Nexus 2 repositories also show the correct snapshot version, such as this one: https://img.shields.io/nexus/s/org.spongepowered/configurate-core?label=dev&server=https%3A%2F%2Foss.sonatype.org, leading me to believe that this issue is Nexus 3 specific.

:link: The badge in question: https://img.shields.io/nexus/s/dev.magicmq/itemapi?server=https%3A%2F%2Frepo.magicmq.dev

:bulb: Possible Solution

I haven't found any possible solution for this issue yet.

magicmq avatar Jan 30 '21 20:01 magicmq

Thanks for putting all the details together @magicmq! Will dig into it on the coming weeks. 😉

PyvesB avatar Jan 30 '21 21:01 PyvesB

I've had a dig around. There doesn't seem to be a way to easily retrieve the latest base version of a snapshot (e.g. 0.6.0-SNAPSHOT). Unlike the Nexus 2 API, Nexus 3 only returns timestamped versions.

I've created a feature request on the Sonatype JIRA tracker: https://issues.sonatype.org/browse/NEXUS-26853. Hopefully it can be addressed and I'll be able to revise our implementation. 😉

PyvesB avatar Feb 28 '21 12:02 PyvesB

Hey @PyvesB, I can't seem to view that feature request on Sonatype's JIRA tracker; it says the issue may have been deleted or I don't have access.

Just wanted to check the status of this and see if Sonatype had the chance to comment on/implement this improvement for Nexus 3.

magicmq avatar Mar 20 '21 07:03 magicmq

The issue is still there. You may need to create an account on their JIRA to be able to see it. However, no one has yet acknowledged the issue. Voting on the ticket or adding a useful comment of some sort may help it get visibility.

PyvesB avatar Mar 20 '21 08:03 PyvesB

Hey guys, any updates on this issue? I tried creating an account and following the exact same link to jira but it shows as deleted or without permissions.

Im-Fran avatar Jul 23 '21 21:07 Im-Fran

Someone from the Sonatype team updated a few fields on the issue back in May, but I've had no news since.

PyvesB avatar Aug 09 '21 08:08 PyvesB

If anyone is looking for a workaround I found one (only works if you have a specific maven repo for your spanshots), I added this url as badge:

https://img.shields.io/badge/dynamic/xml?url={URL_TO_SNAPSHOT_METADATA}&label=Latest%20Snapshot&color=orange&query=.//versioning/latest

In my case I used https://repo.theprogramsrc.xyz/repository/maven-snapshots/xyz/theprogramsrc/SuperCoreAPI/maven-metadata.xml

And I got this: Latest Snapshot

Im-Fran avatar Nov 14 '21 14:11 Im-Fran

If anyone is looking for a workaround I found one (only works if you have a specific maven repo for your spanshots), I added this url as badge:

https://img.shields.io/badge/dynamic/xml?url={URL_TO_SNAPSHOT_METADATA}&label=Latest%20Snapshot&color=orange&query=.//versioning/latest

In my case I used https://repo.theprogramsrc.xyz/repository/maven-snapshots/xyz/theprogramsrc/SuperCoreAPI/maven-metadata.xml

And I got this: Latest Snapshot

It looks like this works because of a recent Nexus enhancement. I tested on OSS 3.34.1-01 and the latest tag does not exist.

Update: I found another workaround. Let's say we have a maven-metadata.xml like this:

<metadata>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<versioning>
<versions>
<version>1.1.3-SNAPSHOT</version>
<version>1.1.4-SNAPSHOT</version>
</versions>
<lastUpdated>20230103231933</lastUpdated>
</versioning>
</metadata>

You can query the latest snapshot with this XPath:

//metadata/versioning/versions/version[last()]

To put it all together you can create a dymanic badge with XML query here at https://shields.io/.

Edit the example here.

chadj2 avatar Jan 03 '23 23:01 chadj2