skip to content

A CI build using a Maven version range keeps resolving 2.2.0 although 2.3.0's JAR and POM sit in the internal hosted repository; what do you check?

level: seniorimportance: should knowfreq 45%

answer

  1. discovery reads a document
  2. artifactId-level metadata file
  3. exact pin versus range
  4. files present, list stale
  5. fix the server, then caches

basics

~20 s

Check the artifactId-level maven-metadata.xml: a version range is expanded from its <versions> list, not by listing directories, so a 2.3.0 that reached storage without a metadata update stays invisible to ranges while an exact 2.3.0 still resolves.

solid answer

~50 s

Maven never lists directories; a range like `[2.0,3.0)` is expanded from the `<versions>` list in the artifactId-level `maven-metadata.xml`. So first fetch that file, and its `.sha1`, straight from the hosted repository and see whether 2.3.0 is listed. If it is missing, the files arrived by a path that did not update the metadata: a copy or import into storage, a generic file upload, or, on a plain HTTP server where the deploying client writes the metadata itself, two deploys overwriting each other's list. A quick proof is to pin exactly 2.3.0: the layout computes that path directly, so it resolves. The fix is on the server: have the repository manager recalculate the metadata where it can, or redeploy through the normal deploy path. If the server's file is right, look in front of it: a group or virtual repository's cached merged metadata, and the build agent's own copy, which Maven re-checks per `updatePolicy` (`daily` by default).

code

xml · 14 lines
xml
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>com.example.billing</groupId>
  <artifactId>invoice-core</artifactId>
  <versioning>
    <latest>2.2.0</latest>
    <release>2.2.0</release>
    <versions>
      <version>2.1.0</version>
      <version>2.2.0</version>
    </versions>
    <lastUpdated>20260921101500</lastUpdated>
  </versioning>
</metadata>

go deeper

for a junior

Remember that Maven discovers versions from maven-metadata.xml in the artifactId directory, not by looking at folders.

for a middle

Explain why an exact version resolves from the layout alone while a range depends on the artifactId-level metadata, and what the versions, latest, release and lastUpdated elements hold.

for a senior

Localise the fault layer by layer: the hosted repository's own metadata and checksum, then the group's cached copy, then the agent's local copy, and name how the version escaped the metadata.

for a principal

Treat every format's index document as the real publish step, and require that artifacts enter repositories only through paths that maintain it, checked after each publish.

## Version discovery reads a document, not a directory A Maven repository has no "list versions" API. The client finds out which versions exist by reading one file: the **artifactId-level `maven-metadata.xml`**, which sits in the artifactId directory (for example `com/example/billing/invoice-core/maven-metadata.xml`) and holds: - `<groupId>` and `<artifactId>`; - `<versioning>` with `<latest>`, `<release>`, a `<versions>` list and `<lastUpdated>`. When a dependency declares a **range** such as `[2.0,3.0)`, the resolver expands it into the list of matching versions from the repositories it uses, and that list comes from this file. An **exact** release version needs no discovery at all: the layout turns `invoice-core:2.3.0` straight into a path. That asymmetry is the most useful diagnostic you have. ## Step 1: read the server's own copy Work from the repository outward, so you know whether the server or something in front of it is wrong: 1. Request `.../invoice-core/maven-metadata.xml` **directly from the hosted repository**, not through a group, and read the `<versions>` list and `<lastUpdated>`. 2. Request its `.sha1` and compare it with the file; the metadata is deployed with checksums like any artifact, and a mismatch can make the client warn or reject the file depending on its checksum policy. 3. Change the build to pin exactly `2.3.0`. If that resolves while the range does not, the files are fine and only discovery is broken. 4. Look at the version directory itself in the repository manager's UI to confirm the JAR, POM and their checksums are where the layout says. ## How a version reaches storage but not the metadata The metadata is a separate file, so anything that writes artifacts without also rewriting it leaves a version that exists and cannot be discovered: - **Copying or importing files** into the repository's storage or a mounted directory, bypassing the deploy path. - **Uploading through a generic file interface** that stores the JAR and POM at the right paths but does not maintain Maven metadata. - **Racing deploys to a plain HTTP or file server.** There the deploying client uploads the artifacts *and* the metadata itself, with a `PUT` for each file. Two builds deploying versions of the same artifact close together can each write a list that lacks the other's version. - **A restore or migration** that brought back artifact files but an older metadata file. ## Fixing it on the server - Prefer a repository manager that **computes Maven metadata itself** for hosted repositories (Artifactory documents calculating metadata for artifacts in its local repositories), so the file is derived from what is stored rather than from whichever client wrote last, and use its recalculation for the affected path where it offers one. - On a plain server, **redeploy** the version through the normal deploy path, or regenerate the file, and redeploy its checksums with it. - Stop the cause: forbid writes into the storage behind the repository, serialize deploys if the server cannot merge them, and add a post-publish check that fetches `maven-metadata.xml` and asserts the new version is listed. ## Then the layers in front of it Once the hosted repository's file is right, a build can still see the old list: - **A group or virtual repository** answers with metadata merged from its members and may serve a cached copy for a while; how long is a proxy and caching setting, covered with dependency proxying. - **The build agent's local repository** keeps its own copy of remote metadata. Maven re-checks it according to the repository's `updatePolicy`, whose choices are `always`, `daily` (the default), `interval:X` and `never`. A long-lived agent can therefore miss a version published since its last check, while a fresh container fetches the current file. ## The same failure in other formats Every format in this leaf has an index document separate from the files, and the same "files present, index stale" failure: | Format | Index document clients read | Symptom when it is stale | |---|---|---| | Maven | artifactId-level `maven-metadata.xml` | ranges miss the version; exact pins work | | npm | the package's packument (`versions`, `dist-tags`) | `latest` or a range resolves to an older version | | Python | the project page under the simple API | installers never see the new file | | NuGet | flat container `{LOWER_ID}/index.json` and registrations | version missing from listings and resolution | | Helm chart repository | `index.yaml` | the chart archive sits on the server but is not offered | The habit that transfers: when a version "exists but will not resolve", read the index document the client reads before you look at the files.

  • Why does pinning exactly 2.3.0 resolve when the range does not?
    An exact release version needs no discovery: the layout turns the coordinates straight into the path of the POM and JAR, and those files are present. A range has to be expanded into candidate versions, and that list comes from the artifactId-level `maven-metadata.xml`, which is where 2.3.0 is missing.
  • How do you stop a version from reaching a Maven hosted repository without its metadata again?
    Make the repository's deploy path the only way in: no writes into its storage, no generic uploads for Maven content. Use a repository manager that maintains Maven metadata for hosted repositories, serialize deploys if the server cannot merge concurrent ones, and add a post-publish step that fetches `maven-metadata.xml` and fails if the new version is not listed.
  • After the hosted repository is fixed, why might builds through the group repository still miss 2.3.0?
    A group or virtual repository serves metadata merged from its members and may keep a cached copy until its metadata cache expires, and a long-lived build agent keeps its own copy, re-checked per `updatePolicy` (`daily` by default). Check each layer in turn, starting from the hosted repository.

  • Maven lists the version directories to find the newest match for a range.
  • If the JAR is in storage, every build can resolve it by range.
  • Clearing the CI agent's local repository always fixes a range that misses a version.
  • maven-metadata.xml only matters for SNAPSHOT builds.
  • An exact version would fail the same way, since it also needs maven-metadata.xml.