{"record":{"id":"71a1804dd2580d01","repo":"theonedev/onedev","slug":"duplicate-dependency-build-dependencybuild-ge","errorCode":null,"errorMessage":"Duplicate dependency build '\" + dependencyBuild.getReference().toString(null) + \"'","messagePattern":"Duplicate dependency build '\" \\+ dependencyBuild\\.getReference\\(\\)\\.toString\\(null\\) \\+ \"'","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/job/DefaultJobService.java","lineNumber":431,"sourceCode":"\t\t\t\t}\n\n\t\t\t\tBuild dependencyBuild = dependency.getBuildProvider().getBuild(dependencyProject);\n\t\t\t\tif (dependencyBuild == null) {\n\t\t\t\t\tString errorMessage = String.format(\"Unable to find dependency build in project '\"\n\t\t\t\t\t\t\t+ dependencyProject.getPath() + \"'\");\n\t\t\t\t\tthrow new ExplicitException(errorMessage);\n\t\t\t\t}\n\n\t\t\t\tAccessProject projectPermission = new AccessProject();\n\t\t\t\tif (!dependencyProject.isPermittedByLoginUser(projectPermission)\n\t\t\t\t\t\t&& !subject.isPermitted(new ProjectPermission(dependencyProject, projectPermission))) {\n\t\t\t\t\tthrow new ExplicitException(\"Unable to access dependency build '\"\n\t\t\t\t\t\t\t+ dependencyBuild.getReference().toString(null) + \"': permission denied\");\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (build.getDependencies().stream()\n\t\t\t\t\t\t.anyMatch(it -> it.getDependency().equals(dependencyBuild))) {\n\t\t\t\t\tthrow new ExplicitException(\"Duplicate dependency build '\"\n\t\t\t\t\t\t\t+ dependencyBuild.getReference().toString(null) + \"'\");\n\t\t\t\t}\n\n\t\t\t\tBuildDependence dependence = new BuildDependence();\n\t\t\t\tdependence.setDependency(dependencyBuild);\n\t\t\t\tdependence.setDependent(build);\n\t\t\t\tdependence.setArtifacts(dependency.getArtifacts());\n\t\t\t\tdependence.setDestinationPath(dependency.getDestinationPath());\n\t\t\t\tbuild.getDependencies().add(dependence);\n\t\t\t}\n\n\t\t\tbuildService.create(build);\n\t\t\tbuildSubmitted(build);\n\n\t\t\tLong buildId = build.getId();\n\t\t\tLong projectId = project.getId();\n\t\t\tLong requestId = PullRequest.idOf(request);\n\t\t\tLong issueId = Issue.idOf(issue);","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/job/DefaultJobService.java#L413-L449","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove duplicate entries from the dependencies section of the build spec so each build is referenced once.","Before adding programmatically, check whether the dependency already exists and skip if present.","If merging specs, deduplicate the dependency list by build reference before submission."],"exampleFix":"// before (.onedev-buildspec.yml)\ndependencies:\n  - build: '123'\n  - build: '123'\n\n// after\ndependencies:\n  - build: '123'","handlingStrategy":"validation","validationCode":"// Java, before adding a dependence\nboolean alreadyDepends = build.getDependencies().stream()\n        .anyMatch(it -> it.getDependency().equals(dependencyBuild));\nif (!alreadyDepends) {\n    BuildDependence d = new BuildDependence();\n    d.setDependency(dependencyBuild);\n    d.setDependent(build);\n}","typeGuard":null,"tryCatchPattern":"try {\n    jobService.submit(build);\n} catch (ExplicitException e) {\n    if (e.getMessage().startsWith(\"Duplicate dependency build\")) {\n        // dedupe spec dependencies and resubmit\n    }\n}","preventionTips":["Deduplicate dependency lists when merging generated specs","Idempotently guard programmatic dependency additions with a membership check","Review the dependencies section after copy-pasting spec templates"],"tags":["duplicate","build-dependency","ci-pipeline","configuration"],"backgroundTag":"file-already-exists","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}