Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to force maven to copy resource folder changes incrementally?

I'm using Maven 2.2.1 and m2eclipse.

I have two resource folders.

When I save a change to any file in any of the resource folders, the Maven incremental build kicks off and re-copies ALL files in both resource folders to the target folders.

This behavior would be fine if there were a relatively small number of files in the resource folders - but there are enough that the copy can take several minutes.

Is there a way to force maven to be more selective in its incremental build and copy only those resources that were changed?

like image 250
Jared Avatar asked Oct 19 '10 15:10

Jared


1 Answers

I chased the problem down to org.codehaus.plexus.util.FileUtils.copyFile() method. It is this method that is called by the maven-resource-plugin to ultimately copy the resource; the copyFile() method takes an 'overwrite' parameter, which the resource-plugin does pass in (and the default is indeed false), BUT...

The copyFile() method ignores the 'overwrite' parameter if the list of filter-wrappers passed is non-empty! And if you have filtering set to true for your resources, this list is indeed non-empty.

I can understand the reasoning behind copyFile() ignoring the 'overwrite': just because the destination file is newer does not mean that new filtered-file will be the same (i.e. the values for the variables in your resource file may have been changed since the last filtering).
Ignoring the 'overwrite' flag is "convenient" for the FileUtils implementor. But this comes at a great price; a single resource file unnecessarily updated can trigger off time-consuming but redundant processes (i.e. rebuilding a jar-with-dependencies in my case). This may only be a few seconds but can be enough to disrupt the flow of an intensive code-compile-test cycle.

I looked for open bug on FileUtils but did not find any. This was bugging me so I had to chase it down but I can't spend more time on it right now... in few days I would like to file a bug report (may just be quicker to implement the right solution); if anyone can post links to the appropriate bug-tracking/reporting system I would appreciate it.

like image 155
R.G. Avatar answered Sep 29 '22 03:09

R.G.