theonedev/onedev · error · ExplicitException

Duplicate dependency build '" + dependencyBuild.getReference

Error message

Duplicate dependency build '" + dependencyBuild.getReference().toString(null) + "'

What it means

Thrown by DefaultJobService.doSubmit when the build being submitted already lists the same dependency build more than once. OneDev stores dependencies as BuildDependence records and rejects duplicates to keep the dependency graph acyclic and unambiguous. The message includes the duplicate build's reference string.

Source

Thrown at server-core/src/main/java/io/onedev/server/job/DefaultJobService.java:431

				}

				Build dependencyBuild = dependency.getBuildProvider().getBuild(dependencyProject);
				if (dependencyBuild == null) {
					String errorMessage = String.format("Unable to find dependency build in project '"
							+ dependencyProject.getPath() + "'");
					throw new ExplicitException(errorMessage);
				}

				AccessProject projectPermission = new AccessProject();
				if (!dependencyProject.isPermittedByLoginUser(projectPermission)
						&& !subject.isPermitted(new ProjectPermission(dependencyProject, projectPermission))) {
					throw new ExplicitException("Unable to access dependency build '"
							+ dependencyBuild.getReference().toString(null) + "': permission denied");
				}
				
				if (build.getDependencies().stream()
						.anyMatch(it -> it.getDependency().equals(dependencyBuild))) {
					throw new ExplicitException("Duplicate dependency build '"
							+ dependencyBuild.getReference().toString(null) + "'");
				}

				BuildDependence dependence = new BuildDependence();
				dependence.setDependency(dependencyBuild);
				dependence.setDependent(build);
				dependence.setArtifacts(dependency.getArtifacts());
				dependence.setDestinationPath(dependency.getDestinationPath());
				build.getDependencies().add(dependence);
			}

			buildService.create(build);
			buildSubmitted(build);

			Long buildId = build.getId();
			Long projectId = project.getId();
			Long requestId = PullRequest.idOf(request);
			Long issueId = Issue.idOf(issue);

View on GitHub (pinned to d44925c47c)

Solutions

  1. Remove duplicate entries from the dependencies section of the build spec so each build is referenced once.
  2. Before adding programmatically, check whether the dependency already exists and skip if present.
  3. If merging specs, deduplicate the dependency list by build reference before submission.

Example fix

// before (.onedev-buildspec.yml)
dependencies:
  - build: '123'
  - build: '123'

// after
dependencies:
  - build: '123'
Defensive patterns

Strategy: validation

Validate before calling

// Java, before adding a dependence
boolean alreadyDepends = build.getDependencies().stream()
        .anyMatch(it -> it.getDependency().equals(dependencyBuild));
if (!alreadyDepends) {
    BuildDependence d = new BuildDependence();
    d.setDependency(dependencyBuild);
    d.setDependent(build);
}

Try / catch

try {
    jobService.submit(build);
} catch (ExplicitException e) {
    if (e.getMessage().startsWith("Duplicate dependency build")) {
        // dedupe spec dependencies and resubmit
    }
}

Prevention

When it happens

Trigger: Calling submit/dependencyBuild when build.getDependencies() already contains a dependence whose getDependency().equals(dependencyBuild) — i.e., declaring the same build number twice in the dependencies section, or re-submitting a spec that appends rather than replaces dependencies.

Common situations: Copy-pasting dependency entries in .onedev-buildspec.yml; programmatically adding dependencies in a loop without deduplication; template-generated specs that merge dependency lists; retry logic that mutates an existing build's dependencies again.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/71a1804dd2580d01. Report an issue: GitHub.