Skip to content

[Question] - Retrieving sbt plugin versions from hosted Sonatype Nexus #1874

@ckipp01

Description

@ckipp01

At my work we use Scala Steward to update all of our internal dependencies. We use a hosted Sonatype Nexus to both have a mirror of Maven Central and also to have our own internal releases Maven repo. From looking through the Scala Steward code it seems that it relies on Coursier to retrieve the list of versions available for the artifact.

https://github.com/scala-steward-org/scala-steward/blob/a2cea0f1f72f13b38f3b5cb01ae3cad04a58aff0/modules/core/src/main/scala/org/scalasteward/core/coursier/VersionsCache.scala#L54

If I understand it right, this is done for artifacts that have a maven-metadata.xml file, but as you know, sbt plugins that are published Maven style don't have one. Which again, to my understanding because of this, Coursier then relies on the directory listing? This is how it seems to work for our maven-central mirror with the sbt-scalafmt plugin. By looking at it with a path like this, I can see an html directory listing of all versions:

https://nexus-redacted.com/repository/maven-public/org/scalameta/sbt-scalafmt_2.12_1.0

Scala Steward (Coursier) is able to correctly gather the versions (again I assume from this and sounds like that from this thread in Steward). However, I'm finding a lot of contradictory information about whether or not this is available on different versions of Nexus3. Plus those that manage our Nexus is saying there is no option to turn this on.

From what I can tell, for our own internal nexus where I'd expect the directory listing to be like the sbt-scalafmt example above, it just 404's.

https://nexus-redacted.com/repository/redacted-releases/redacted/redacted/sbt-redacted_2.12_1.0

There is an html index of sorts at this url:

https://nexus-redacted.com/service/rest/repository/browse/redacted-releases/redacted/redacted/sbt-redacted_2.12_1.0/

However, looking through the code here, I don't believe that will work:

private def versionsFromListing[F[_]](
module: Module,
fetch: Repository.Fetch[F]
)(implicit
F: Monad[F]
): EitherT[F, String, (Versions, String)] = {
val listingUrl = urlFor(modulePath(module)) + "/"
// version listing -> changing (changes as new versions are released)
val listingArtifact = artifactFor(listingUrl, changing = true)
fetch(listingArtifact).flatMap { listing =>
val files = WebPage.listFiles(listingUrl, listing).toVector
val rawVersions = WebPage.listDirectories(listingUrl, listing).toVector
val res =
if (files.contains("maven-metadata.xml"))
Left("maven-metadata.xml found, not listing version from directory listing")
else if (rawVersions.isEmpty)
Left(s"No versions found at $listingUrl")
else {
val parsedVersions = rawVersions.map(Version(_))
val nonPreVersions = parsedVersions.filter(_.items.forall {
case t: Version.Tag => !t.isPreRelease
case _ => true
})
if (nonPreVersions.isEmpty)
Left(s"Found only pre-versions at $listingUrl")
else {
val latest = nonPreVersions.max
Right(Versions(
latest.repr,
latest.repr,
nonPreVersions.map(_.repr).toList,
None
))
}
}
EitherT(F.point(res.map((_, listingUrl))))
}
}

And when Scala Steward attempts to get the available versions of the plugin, it gets none and therefore doesn't send in prs for our internal sbt plugins. Which sort of leads me to believe that because of the lack of directory listing there, Coursier isn't getting the versions? Do you know if it's possible for Coursier to get the versions of an sbt plugin without the directory listing, or does that have to be there? Or could there be another check possible to capture this alternative html view the same way the other is captured?

EDIT: For the time being we just add in a custom release step to create / update the maven-metadata.xml file, but it'd still be great to see if what I mentioned above is the case or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions