{"record":{"id":"63a90927f43c300d","repo":"apache/maven","slug":"error-retrieving-previous-build-number-for-artifac","errorCode":null,"errorMessage":"Error retrieving previous build number for artifact '\" + artifact.getDependencyConflictId() + \"': \" + e.getMessage()","messagePattern":"Error retrieving previous build number for artifact '\" \\+ artifact\\.getDependencyConflictId\\(\\) \\+ \"': \" \\+ e\\.getMessage\\(\\)","errorType":"exception","errorClass":"ArtifactDeploymentException","httpStatus":null,"severity":"error","filePath":"compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/SnapshotTransformation.java","lineNumber":94,"sourceCode":"    }\n\n    @Override\n    public void transformForDeployment(\n            Artifact artifact, ArtifactRepository remoteRepository, ArtifactRepository localRepository)\n            throws ArtifactDeploymentException {\n        if (artifact.isSnapshot()) {\n            Snapshot snapshot = new Snapshot();\n\n            // TODO Should this be changed for MNG-6754 too?\n            snapshot.setTimestamp(getDeploymentTimestamp());\n\n            // we update the build number anyway so that it doesn't get lost. It requires the timestamp to take effect\n            try {\n                int buildNumber = resolveLatestSnapshotBuildNumber(artifact, localRepository, remoteRepository);\n\n                snapshot.setBuildNumber(buildNumber + 1);\n            } catch (RepositoryMetadataResolutionException e) {\n                throw new ArtifactDeploymentException(\n                        \"Error retrieving previous build number for artifact '\" + artifact.getDependencyConflictId()\n                                + \"': \" + e.getMessage(),\n                        e);\n            }\n\n            RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata(artifact, snapshot);\n\n            artifact.setResolvedVersion(\n                    constructVersion(metadata.getMetadata().getVersioning(), artifact.getBaseVersion()));\n\n            artifact.addMetadata(metadata);\n        }\n    }\n\n    public String getDeploymentTimestamp() {\n        if (deploymentTimestamp == null) {\n            deploymentTimestamp = getUtcDateFormatter().format(new Date());\n        }","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/compat/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/transform/SnapshotTransformation.java#L76-L112","documentation":"SnapshotTransformation.transformForDeployment prepares a -SNAPSHOT artifact for deployment and must compute the next build number by reading the repository's existing maven-metadata.xml (resolveLatestSnapshotBuildNumber). If that read throws RepositoryMetadataResolutionException, it is wrapped in ArtifactDeploymentException('Error retrieving previous build number for artifact <dependencyConflictId>: <cause>'), aborting the deploy before any file transfer.","triggerScenarios":"mvn deploy of a SNAPSHOT where the target repository's metadata cannot be fetched: 401/403 because no <server> credentials match the repository id in distributionManagement, repository URL wrong or unreachable, proxy blocking the request, or the repository returning an error page for the metadata path.","commonSituations":"Missing or mislabeled server id in settings.xml versus <distributionManagement><snapshotRepository><id>; CI deploying behind a corporate proxy; typo in the snapshot repository URL; first deploy to a newly created repository whose permissions are wrong.","solutions":["Match the <snapshotRepository><id> in distributionManagement with a <server><id> entry (with username/password/token) in ~/.m2/settings.xml","Confirm the snapshot repository URL from the message's cause is reachable: curl it and expect either metadata XML or a clean 404, not 401/403/HTML","Fix proxy/mirror settings if a middleman intercepts the metadata request","Retry with mvn -U deploy after fixing access so stale local metadata does not mask the repair"],"exampleFix":"<!-- before: distributionManagement id has no matching server -->\n<distributionManagement>\n  <snapshotRepository>\n    <id>snapshots</id>\n    <url>https://repo.example.com/snapshots</url>\n  </snapshotRepository>\n</distributionManagement>\n\n<!-- after: add matching credentials in settings.xml -->\n<servers>\n  <server>\n    <id>snapshots</id>\n    <username>ci-user</username>\n    <password>${env.REPO_TOKEN}</password>\n  </server>\n</servers>","handlingStrategy":"try-catch","validationCode":"// Before mvn deploy, verify credentials exist for each distributionManagement repo id\nSettings settings = settingsBuilder.buildSettings();\nfor (String serverId : List.of(distMgmtSnapshotRepoId, distMgmtReleaseRepoId)) {\n    Server server = settings.getServer(serverId);\n    if (server == null || isBlank(server.getUsername())) {\n        throw new IllegalStateException(\"No credentials configured in settings.xml for server id '\" + serverId + \"'\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    deployer.deploy(...);\n} catch (ArtifactDeploymentException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Error retrieving previous build number\")) {\n        Throwable cause = e.getCause(); // RepositoryMetadataResolutionException with HTTP details\n        failBuildWithHint(\"Cannot read snapshot metadata from the deploy repository — check server id '\"\n            + repo.getId() + \"', credentials and URL\", cause);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Keep <server><id> entries in settings.xml in exact lockstep with distributionManagement repository ids — assert this in a pre-deploy CI step","Dry-run reachability: curl the snapshot repository metadata URL with the same credentials before deploying","Prefer dedicated CI users with deploy-only permissions to avoid 403 surprises from shared accounts"],"tags":["maven","deployment","snapshot","metadata","authentication","legacy-compat"],"backgroundTag":"artifact-deployment-failed","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}