Friday, October 19, 2007

Ant vs Maven - Round 2


Alright so now i need to programmatically generate files to include in the WEB-INF directory along other static files.

Round two: Defining multiple places for aggregation
Maven lifecycle is pretty well defined (1). To generate my files, i'm using a Mojo (Maven Pojo) attached to the generate-resources phase. Easy enough, pretty cool.

The issue i have now is that i need to generate those files in target directory. I obviously don't want to put my generated files with the sources and the plugin which builds the war files only allows a unique location for such files... I'm doomed, i need to workaround.

For the workaround (thank you Wesley for the tip) i use:


<project>
...
<build>
...
<resources>
<resource>
<directory>${basedir}/target/generated/</directory>
<targetpath>${basedir}/target/${artifactId}-${version}</targetpath>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
...
</build>
</project>


I'm sure there is a bit better to do (how do i reference the target directory ?) but that's the general idea of the workaround.

In ant i would just use 2 filesets and i would be done.
The advantage that Maven is supposed to give me just vanished and i had to use an ant-style solution. So here i cannot really give a winner, except that Maven failed in its promises (can i have my money back ?), i'll still give 1 point to both.
Maven 2 - Ant 1

(1) missing "prepare-package" in the current GA version but included in the coming 2.1. I will need that one, i can trick)

9 comments:

Milos said...

Not sure what Mojo/Maven plugin you are using but most plugins I know that generate stuff take care everything on their own.

Anonymous said...

I like maven, I really do, but I don't like having to occasionally waste hours browsing the (often poorly organized) docs to get it to do what I need.

On the other hand, it is a genuinely powerful tool. I've always eventually found out how to do what I needed, and -- when all else fails -- you can always drop down to good old ant using the maven-antrun-plugin plugin giving you the best of both worlds....

Thomas Heute said...

milos, i used the standard plugins.

anonymous, you just pointed out the argument i hate most about Maven evangelists, "-- when all else fails -- you can always drop down to good old ant using the maven-antrun-plugin plugin". So why not using the stuff that works at first ? With ant, you can call Maven too.

And i won't claim that Windows is great because you can install virtualization tools and run Linux. (Or the opposite)

Thanks for your comments

Anonymous said...

Thomas,

It's not that ant works and maven doesn't, it's just that it can be a pain to get it to work. Like I said, I've always eventually figured out the maven way of accomplishing what I need, so embedding ant code in my pom isn't something I generally do.

That being said, I'm more comfortable embedding a bit of ant script in my pom.xml, than using maven tasks in an ant script.

My logic being maven sits higher up in the tool stack than ant. It's analogous I think to using JNI to call a native function in a java application vs. embedding an entire jvm in your c application just to call a single java function. Hope that makes sense ...

Thomas Heute said...

Yes it makes sense, i guess it depends how much 'ant' you end-up including at the end.

Documentation is my round 3, you bet who will win/loose ;)

boomtown15 said...

I implemented a Developer Environment using Ant and am currently setting up an environment to use Maven. In my experience Ant worked fine, but was very cumbersome and required more overhead than Maven in most cases. If I had to compare them I would go with Maven hands down. Ant's lack of dependency management is its downfall. Other than that I thought Ant was a great tool. Maven also has seamless integration with other Apache Maven tools like Archiva (Maven repository manager) and Continuum (build tool). Ant is very simple and easy to use for small projects but once you have several developers involved it becomes cumbersome to manage and maintain all the dependencies.

Thomas Heute said...

Boomtown, yes the dependency mechanism of Maven is nice, at JBoss we created our own dependency mechanism and a central repository which worked just fine. Now you have ivy that you can use with ant to do the same things.
I often hear that ivy+ant is the best answer for flexibility and avoiding dependency hell but never gave a try myself to Ivy. And Ivy has support for iBiblio, so many libs are already available.

Anonymous said...

It is certainly interesting for me to read the blog. Thanks for it. I like such topics and anything that is connected to them. I would like to read a bit more on that blog soon.

Anonymous said...

It was certainly interesting for me to read the blog. Thank you for it. I like such topics and anything that is connected to this matter. I definitely want to read a bit more soon.