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.
[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 centralCommon 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.
mvn -B dependency:resolve # confirm everything resolves
mvn -B package # then copy-dependencies can copy themPoint copy-dependencies at a writable directory
Ensure the output directory exists and is writable for the job user.
<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
~/.m2so the dependencies the goal copies are already present.