- dependency:copy-dependencies is used to copy a dependency artifact that is part of the same multi-module build.
- The compile phase is executed, but not the package phase.
An example of this scenario is using maven-eclipse-plugin to import a Maven project with generated test (re)sources. In this case, one would execute "mvn generate-test-resources eclipse:eclipse" to make sure that the generated (re)sources are imported into the workspace (by default, maven-eclipse-plugin executes generate-sources and generate-resources, but not generate-test-sources and generate-test-resources).
Result: The build fails with the following error:
Steps to reproduce:
- Unpack the attached test project and build the entire project once with "mvn install".
- Execute "mvn generate-resources" from the root project -> success (because the compile phase is not executed)
- Execute "mvn package" from the root project -> success (because the package phase is executed)
- Execute "mvn generate-test-resources" from the root project -> fails (because the compile phase is executed, but not the package phase)
- Execute "mvn generate-test-resources" in project2 -> success (because the dependency is not part of the same build)
Root cause analysis: In the scenario described above (compile phase executed, package phase not executed), Artifact#getFile() points to the target/classes directory instead of the output artifact. dependency:copy-dependencies doesn't detect this situation and blindly attempts to execute the copy operation. This fails with the error message shown above. Note that even if the operation didn't fail, it would produce an unexpected result.
Proposed fix (see attached patch): Change maven-dependency-plugin to detect this situation and let it replace the original Artifact object by a new one resolved from the repository (which would then refer to the artifact generated by a previous build, exactly as in the mvn generate-resources case).