Search code examples
mavenmaven-dependency-pluginmaven-resources-plugin

How to stop Maven from overwriting if the destination exists


I have a directory in a dependency, that I want copied in src/main/webapp/mypath during the initialize phase. But I want it to be copied exactly and only once, meaning that:

  • if src/main/webapp/mypath doesn't exist, then copy from dependency
  • if src/main/webapp/mypath exists, then never ever copy from dependency even if the one in the dependency is newer. If exists, don't overwrite it. Never.

I tried a couple of approaches with copy-resources and dependency:unpack but maven will always overwrite if mypath coming from the dependency is newer / updated even if I set to false every possible overwrite* configuration I'm aware of.

Any advice or RTFM + link to a manual I didn't read so far?


Solution

  • You can use profiles:

    <profiles>
      <profile>
        <activation>
          <file>
            <missing>src/main/webapp/mypath</missing>
          </file>
        </activation>
        ... copy ...
      </profile>
    </profiles>