Maven Dependency Plugin
  1. Maven Dependency Plugin
  2. MDEP-259

copy-dependencies fails with "Error copying artifact from .../target/classes to .../classes"

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 2.0, 2.1
    • Fix Version/s: None
    • Component/s: copy, copy-dependencies
    • Labels:
      None
    • Environment:
      Maven 2.0.9
      maven-dependency-plugin 2.0, 2.1 or 2.2-SNAPSHOT (r922616)
    • Testcase included:
      yes
    • Patch Submitted:
      Yes
    • Number of attachments :
      2

      Description

      Scenario:

      • 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:

      [INFO] [dependency:copy-dependencies {execution: default}]
      [INFO] Copying classes to /Users/veithen/dev/maven/axis/axis2/modules/fastinfoset/target/repo/modules/classes
      [INFO] ------------------------------------------------------------------------
      [ERROR] BUILD ERROR
      [INFO] ------------------------------------------------------------------------
      [INFO] Error copying artifact from /Users/veithen/dev/maven/axis/axis2/modules/addressing/target/classes to /Users/veithen/dev/maven/axis/axis2/modules/fastinfoset/target/repo/modules/classes
      
      Embedded error: /Users/veithen/dev/maven/axis/axis2/modules/addressing/target/classes (No such file or directory)

      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).

        Issue Links

          Activity

          Hide
          Dustin Parker added a comment -

          I'm watching this bug because of the Cobertura plugin. We updated Sonar and our builds started failing. I noticed that this error was happening during code coverage analysis (in our WAR module). Switching to JaCoCo worked around the problem.

          Show
          Dustin Parker added a comment - I'm watching this bug because of the Cobertura plugin. We updated Sonar and our builds started failing. I noticed that this error was happening during code coverage analysis (in our WAR module). Switching to JaCoCo worked around the problem.
          Hide
          Ian Brandt added a comment - - edited

          Andreas,

          Would you be able to elaborate at all on your comment:

          ...my proposed change no longer works on Maven 3 because of some subtle changes in the behavior of ArtifactResolver.

          I'm going to take a stab at implementing a fix for this, so any details you could provide would be helpful.

          Show
          Ian Brandt added a comment - - edited Andreas, Would you be able to elaborate at all on your comment: ...my proposed change no longer works on Maven 3 because of some subtle changes in the behavior of ArtifactResolver. I'm going to take a stab at implementing a fix for this, so any details you could provide would be helpful.
          Hide
          Herve Boutemy added a comment -

          duplicate of MDEP-187: closing this duplicate will help focus everybody's energy

          Show
          Herve Boutemy added a comment - duplicate of MDEP-187 : closing this duplicate will help focus everybody's energy
          Hide
          Andreas Veithen added a comment -

          @Ian: Sorry, I did that several months ago and I don't remember the details.

          Show
          Andreas Veithen added a comment - @Ian: Sorry, I did that several months ago and I don't remember the details.
          Hide
          Ian Brandt added a comment -

          @Andreas: No worries. I'm going to work on some tests to better understand how the resolver behaves in various reactor scenarios. I'll see if I can't rediscover the issue you encountered.

          Show
          Ian Brandt added a comment - @Andreas: No worries. I'm going to work on some tests to better understand how the resolver behaves in various reactor scenarios. I'll see if I can't rediscover the issue you encountered.

            People

            • Assignee:
              Unassigned
              Reporter:
              Andreas Veithen
            • Votes:
              29 Vote for this issue
              Watchers:
              28 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: