4

We are using the dependency:copy goal of Apache Maven Dependency Plugin which has three overwrite settings:

  • overWriteIfNewer: Overwrite if newer
  • overWriteReleases: Overwrite release artifacts
  • overWriteSnapshots: Overwrite snapshot artifacts

The only documentation I've found are the short sentences above.

When do these settings count, when do they produce different output? What are the use-cases of these settings? What should I consider before setting them true or false?

palacsint
  • 28,416
  • 10
  • 82
  • 109

1 Answers1

5

See the Overwrite Rules on the plugin's Usage page:

Artifacts are copied or unpacked using the following rules:

  • If the artifact doesn't exist in the destination, then copy/unpack it.

    Otherwise:

  • For copy/unpack mojo only: if artifactItem / overWrite or overWrite is true, then it will force an overwrite.

  • Releases check the overWriteReleases value (default = false). If true, then it will force an overwrite.
  • Snapshots check the overWriteSnapshots value (default = false). If true, then it will force an overwrite.
  • If none of the above is set to true, then it defaults to the overWriteIfNewer value (default = true). This value, if true, causes the plugin to only copy if the source is newer than the destination (or it doesn't exist in the destination). (for unpack, this checks the existence of the marker file, created in the markersDirectory path. To avoid unexpected behavior after mvn clean, this path should normally be contained within the /target hierarchy.)

Examples:

  • ...
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • In the case of overWriteIfNewer : what's newer? I've had some disturbing results thinking this was based on the version of the artifact. Ended up having commons-lang 1.0.1 (transitive) copied besides having commons-lang 2.4 in some dependencies. And that was using stripVersion to true, when setting it to false the dependencies were copied multiple times (so I ended with both 1.0.1 and 2.4) – François Dupire Apr 07 '20 at 17:53
  • @François Please file a new question with the relevant parts of your POMs.I tried it here with some test projects and only one version of a transitive dependency that had referenced two of them is copied: The one whose direct dependency comes first in the `` section of the POM on that `mvn dependency:copy` is run. (If you're using Eclipse: The _Dependency Hierarchy_ tab of the POM editor mentions at the one declared later: "_(omitted for conflict with x.y.z)_". ). If a dep. is declared both direct and transitive (with different versions) the version of the direct dep. is taken. – Gerold Broser Apr 08 '20 at 13:42