Skip to content
Latchkey

Maven "Failed to execute goal ... copy-dependencies" - Fix in CI

The maven-dependency-plugin’s copy-dependencies goal could not copy the project’s dependencies into the output directory. Either a dependency could not be resolved to copy, or the target outputDirectory is not writable.

What this error means

The build fails at the copy-dependencies goal (often bound to package) with Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:<v>:copy-dependencies, and a cause naming an unresolved artifact or a directory it could not write.

mvn output
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-dependency-plugin:3.6.1:copy-dependencies
(copy-deps) on project app: Unable to resolve artifact:
Could not find artifact com.example:lib:jar:2.3.1 in central

Common causes

A dependency to copy cannot be resolved

copy-dependencies must resolve every dependency before copying it. A missing or unreachable artifact fails the goal, exactly like ordinary resolution.

Output directory unwritable or path wrong

If the configured outputDirectory (e.g. ${project.build.directory}/lib) is read-only or its parent does not exist, the plugin cannot write the copied jars.

How to fix it

Resolve the missing dependency first

Fix resolution before copying - declare the repo or pin a published version.

Terminal
mvn -B dependency:resolve   # confirm everything resolves
mvn -B package              # then copy-dependencies can copy them

Point copy-dependencies at a writable directory

Ensure the output directory exists and is writable for the job user.

pom.xml
<configuration>
  <outputDirectory>${project.build.directory}/lib</outputDirectory>
  <overWriteReleases>false</overWriteReleases>
</configuration>

How to prevent it

  • Ensure all dependencies resolve before binding copy-dependencies in the lifecycle.
  • Write copied jars under target/, which CI always treats as writable.
  • Cache ~/.m2 so the dependencies the goal copies are already present.

Frequently asked questions

What causes ""Failed to execute goal ... copy-dependencies""?
copy-dependencies must resolve every dependency before copying it. A missing or unreachable artifact fails the goal, exactly like ordinary resolution.
How do I fix "Failed to execute goal ... copy-dependencies"?
Fix resolution before copying - declare the repo or pin a published version.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card