Maven & Eclipse target folder + validation stabbyness

Does using Maven with Eclipse make you stabby when you spend an hour waiting for Eclipse to finish validating files? You may not realize it, but Eclipse is indexing/validating files inside of your project’s target folders! Yes kids, this is annoying and time consuming. The target folders also end up showing results in the “Open Type” and “Open Resource” windows. I’m sure we’ve all experienced the duplicate results when searching for a class or resource.

Why does it do this? Eclipse has a feature built in that will, by default, exclude folders that have been marked as “derived”. Normally folders like your source output folders (bin for example) are marked for you. Well, Eclipse doesn’t automatically mark the target folder as “derived” so it treats it like a regular folder. Right click your target folder in Eclipse and click the check box for “derived” – magically the folder is now excluded even from the Open Type and Open Resource windows.

But wait.

Next time you run a Maven “clean”, the target folder is deleted and the check box reset for derived. How do you avoid that? In your parent project (or current project if you have a single module) add the following to your plugin definitions:

This will force Maven to use version 2.4.1 of the “clean” plugin – if you’re using Maven 3 you can probably remove the version line. After version 2.3 of the plugin, excludeDefaultDirectories became available. This little gem will only delete the target content and leave the folder alone for you.

Enjoy!

2 thoughts on “Maven & Eclipse target folder + validation stabbyness

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s