views:

130

answers:

5

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?

A: 

Maven is a build tool. It doesn't actually do incremental builds. Another 3rd application might listen for changes and do builds via maven. You should look into what that application is that is doing the incremental builds. In this case, I think your IDE is doing the builds.

Amir Raminfar
This is wrong. Maven does incremental builds just fine. Try a mvn install after changing a source code file and it will just recompile that file..
Manfred Moser
I tried doing mvn install again and I see what you are talking about. But again I don't think that's what the question is about. You would still have to issue mvn install when you are done. In this case, the environment/IDE is calling mvn install automatically. ps. not doing a clean before each build can result in not removing files that you removed in src.
Amir Raminfar
A: 

There might be an option in the Maven resource plugin configuration to do that but I have not found any. If I were you I would split up the resources and move them out into separate modules that you depend on. Then you just rebuild the module that you changed files in and not the others and things will be much faster..

I would also try Maven 3.0 that was just released. It is a lot faster and will improve your situation in this and other aspects as well.

Manfred Moser
+1  A: 

Try setting the overwrite parameter of the Maven resources plugin to false. http://maven.apache.org/plugins/maven-resources-plugin/resources-mojo.html#overwrite

Edited: this parameter exists since Maven resources plugin version 2.3. @Jared: Please check your version.

Peter Knego
The documentation states it is `false` by default
matt b
Docs says "Since: 2.3". As I see original poster has Maven 2.2.1.
Peter Knego
2.3 is the version of the plugin, not the maven version (there is no maven 2.3).
Pascal Thivent
You are quite right. My bad.
Peter Knego
+1  A: 

You can try updating to the latest version of m2eclipse and Maven 3. There is a new Maven plugin API that tells m2eclipse what files been affected by the Maven plugin. I believe resource plugin been updated to that API (but make sure overwrite setting is NOT set to true in resource plugin configuration).

Eugene Kuleshov
How does this work then if you do not have Eclipse? I don't think that Eclipse part has anything to do with Maven copying resources to target dir.
Peter Knego
A: 

Assuming you don't want to update, it appears that you'd need to write your own version of the resources plugin.

This doesn't look like it would be too hard (some incomplete source code is here: http://maven.apache.org/plugins/maven-resources-plugin/xref/index.html) and you could include your own custom configuration parameter to modify the overwrite behaviour of the MavenResourcesExecution class.

If you were feeling community minded, you could submit the patch back into the plugin repository to allow others to take advantage of the update.

Gary Rowe