Tuesday, 4 September 2007

Maven defaults is missing something

Mavens defined conventions for resources as follows:

  • Java files in src/main/java
  • All resources in src/main/resources
And on the surface it seems fine. Keep your java source and resources separated and clean.
But for some resources it makes sence to keep them "close" to the java class using it - say in the same package. I could do that by duplicating package structure in my resources directory, but that would be repeating myself and breaking the good old DRY principle. But furthermore and much more important I risk to miss the resource files when refactoring my build (renaming packages, moving classes).

So I always end up overwriting the resources definition in my pom.xml to something like this:
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${basedir}/src/main/java</directory>
</resource>
</resources>
</build>
I have been one of the defenders of mavens conventions, but this time it seems to be missing something.
Can anyone tell me why this isn't the default in maven?
I can't be the only one placing resources along side with my java files.

3 comments:

Eugene Kuleshov said...

The main reason to separate resources from other sources is that this way it is much faster to copy or filter them out.

Jacob von Eyben said...

I agree that speed in build turnaround time is essential - but is it really that time consuming?

I must say I haven't been blaming copy and filtering as the root cause of the slow builds I have been puzzling with.

Tim O'Brien said...

I see where Eugene is coming from and I see where you are coming from Jacob. I often wish that someone just forked Maven and created a distribution with another set of assumptions, then we'd just see who's assumptions won out in the free market.