8

When i execute a clean & build on a project, Maven copies all resources to the target folder but with the time stamp of the creation, not with the time stamps of the original files in the src/main/resources folder. Is it possible to somehow instruct it to keep the original time stamps?

The cause why this is problematic for us is that the software we are developing has a database migration in startup time and we like to keep it executing on developer machines. But because of the ever changing time stamps this introduce unnecessary resource reloads to the database.

NagyI
  • 5,907
  • 8
  • 55
  • 83
  • 1
    I havent tried it myself, but there's a [copy plugin] (http://evgeny-goldin.com/wiki/Copy-maven-plugin#.3CskipIdentical.3E) with some control over which files are included based on changed timestamp. But I guess this would lead to uncomplete builds also. – Masse Jan 24 '13 at 14:38

2 Answers2

2

I don't think it is possible using default functionality of Maven resources plugin.

Can you change the path where the files are loaded from at runtime (probably by making it configurable per environment)? If so, then perhaps you can use ant with maven and use ant's copy task which has a preservelastmodified property.

The intent being that Maven's resources handling would continue to work as usual, but the files would also be copied every build to a separate location used by the runtime.

kaliatech
  • 17,579
  • 5
  • 72
  • 84
1

Solution is to use ant's copy task. This is done in 2 steps: 1) exlude from the normal processing that files for which we would like to preserve the date (in this example I process test-resources. The same applies for build resources):

<testResources>
    <testResource>
        <directory>src/test/resources</directory>
        <excludes>
            <exclude>**/some-files*/**</exclude>
        </excludes>
    </testResource>
</testResources>

2) the second step is to copy them with ant task using the mave ant plugin:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <phase>process-test-resources</phase>
            <configuration>
                <tasks>
                    <copy todir="${project.build.testOutputDirectory}" preservelastmodified="true">
                        <fileset dir="src/test/resources">
                            <include name="**/some-file*/**"/>
                        </fileset>
                    </copy>                            
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
lvr123
  • 524
  • 6
  • 24