apache/maven · error · InvalidRepositoryException

Repository identifier missing

Error message

Repository identifier missing

What it means

Thrown by LegacyRepositorySystem.buildArtifactRepository(Repository) when a repository definition carries a null or empty id. Maven requires the repository id because it is the join key for <server> credentials, mirror selection and distribution management, so the model is rejected with InvalidRepositoryException before an ArtifactRepository is created. The exception's repository id is passed as the empty string, since none exists.

Source

Thrown at compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java:692

            throws ArtifactTransferFailedException {
        try {
            wagonManager.putRemoteFile(
                    repository, source, remotePath, TransferListenerAdapter.newAdapter(transferListener));
        } catch (org.apache.maven.wagon.TransferFailedException e) {
            throw new ArtifactTransferFailedException(getMessage(e, "Error transferring artifact."), e);
        }
    }

    //
    // Artifact Repository Creation
    //
    @Override
    public ArtifactRepository buildArtifactRepository(Repository repo) throws InvalidRepositoryException {
        if (repo != null) {
            String id = repo.getId();

            if (id == null || id.isEmpty()) {
                throw new InvalidRepositoryException("Repository identifier missing", "");
            }

            String url = repo.getUrl();

            if (url == null || url.isEmpty()) {
                throw new InvalidRepositoryException("URL missing for repository " + id, id);
            }

            ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy(repo.getSnapshots());

            ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy(repo.getReleases());

            return createArtifactRepository(id, url, getLayout(repo.getLayout()), snapshots, releases);
        } else {
            return null;
        }
    }

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Add a unique, non-empty <id> to the offending <repository> element in the POM (check <repositories>, <pluginRepositories>, <profiles>, and <distributionManagement>)
  2. If you build the model in code, call repository.setId("my-repo") before invoking buildArtifactRepository
  3. Re-run with mvn help:effective-pom to confirm every injected repository now carries an id
  4. Enable XML schema validation in your editor so an incomplete <repository> block is flagged while editing

Example fix

<!-- before -->
<repositories>
  <repository>
    <url>https://repo.example.com/maven</url>
  </repository>
</repositories>

<!-- after -->
<repositories>
  <repository>
    <id>example</id>
    <url>https://repo.example.com/maven</url>
  </repository>
</repositories>
Defensive patterns

Strategy: validation

Validate before calling

import org.apache.maven.model.Repository;

boolean isRepositoryDefinitionValid(Repository repo) {
    return repo != null
        && repo.getId() != null && !repo.getId().isEmpty();
}

// before building:
if (!isRepositoryDefinitionValid(repo)) {
    throw new IllegalArgumentException("Repository definition is missing an id: " + repo);
}

Try / catch

try {
    ArtifactRepository artifactRepo = legacyRepositorySystem.buildArtifactRepository(repo);
} catch (InvalidRepositoryException e) {
    // covers both missing-id and missing-url; e.getMessage() says which
    log.warn("Rejected repository definition: {}", e.getMessage());
    throw new BuildConfigurationException("Fix POM repository declaration", e);
}

Prevention

When it happens

Trigger: Calling buildArtifactRepository(repo) (directly or through DefaultArtifactRepositoryFactory / legacy profile injection) with a Model Repository whose getId() returns null or "" — i.e. a POM <repository> or <pluginRepository> block that omits <id> entirely.

Common situations: Hand-edited POM with a <repository> that lists only <url> and <releases>/<snapshots>; snippets copied from documentation or Stack Overflow that drop the <id> element; programmatic model building (Maven Model Builder API, flatten plugins, code generators) that forgets repository.setId(...).

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/0d822a718ac2b7f2. Report an issue: GitHub.