Question

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?

Was it helpful?

Solution

You can use profiles:

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

OTHER TIPS

As described by @William, you can use ant plugin, export the property to maven context and skip the task if "true".

Here is the code:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <phase>validate</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <exportAntProperties>true</exportAntProperties>
                <target>
                    <available file="src/main/resources/my-data" type="dir"
                                                   property="dir-exits"/>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-zip-dependencies</id>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <skip>${dir-exists}</skip>
                <artifactItems>
                    <artifactItem>
                        <groupId>com.mygroup</groupId>
                        <artifactId>myartifactid</artifactId>
                        <includes>**/*.json</includes>                                                       <outputDirectory>src/main/resources/</outputDirectory>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top