Two Laptop Bag*
The moose likes Ant, Maven and Other Build Tools and the fly likes Should i move my builds from ANT to Maven? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Should i move my builds from ANT to Maven?" Watch "Should i move my builds from ANT to Maven?" New topic
Author

Should i move my builds from ANT to Maven?

Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
I need some opinion on this. I had a brief look @ maven yesterday and i wonder if I s'd be considering this?
Is Maven so compelling?
If i just have to run my dailiy builds, start my server and run my unit tests, report code coverage (which my ANT script is already doing), s'd i be moving to Maven in the first place?
Any inputs w'd be highly appreciated.
Can someone comment on other advantages maven offers. W'd Maven replace Ant someday?
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
What follows is just my opinion and experience. Mileage may vary.
Moving an existing project from Ant to Maven can be rough. How rough depends on how your Ant build is structured. We tried doing this on a project and gave up because our build was so much different than how Maven prescribes things. That's not to say that it couldn't be done--we just decided that it wasn't worth the effort.
On the other hand, I'm working a different project and started using Maven from the beginning and am loving it.
There's nothing Maven does that can't also be done in Ant. It's just that Maven abstracts away many of the common things that go on in a build. The good news about that is that your build files (project.xml and maven.xml) will be significantly smaller than the Ant build file (build.xml).
Here's the gotcha: Maven accomplishes all this because it dictates a certain structure for your project. You can tweak the structure somewhat, but for the most part, you must adhere to Maven's way of doing things. As a result, if you're a control freak, then you probably won't like Maven.
Think of it this way: Do you prefer a DOS/Unix prompt or do you prefer a GUI? Sure, the GUI's easier, but you lose some control. It's the same thing with Maven and Ant. Once you figure out how Maven thinks, Maven is much easier than Ant...but Ant afford you more control.


Spring in Action - Unleash POJO power in your applications!
Modular Java - Discover the secret weapon to modularity on the Java platform!
XDoclet in Action - Your complete guide to code generation with XDoclet.
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Thanks Craig!.

We tried doing this on a project and gave up because our build was so much different than how Maven prescribes things. That's not to say that it couldn't be done--we just decided that it wasn't worth the effort.

Given that Maven dictates the directory structure of projects, has that prevented you from doing something (from experience) / can you recollect something that cannot be done using Maven (again from experience).
Now coming to the project you are referring to, do you think you could have structured the project the way Maven expects had you adopted Maven earlier?
When you say Maven dictates the *structure*, you mean the way I structure the source code directory / the builds steps?

On the other hand, I'm working a different project and started using Maven from the beginning and am loving it.

Its realize that you are excited about maven. Would it be possible for you to expand a little more on this. Is it because it is easier to use than Ant? I'm sure it has to be more than this. But since i dont have a good understanding of Maven am just curious.
Writing Ant custom tasks seems to be quite simple. I'm sure Maven also allows us to extend it with plugins. Is it as simple as ANT? and can be easily plugged-in as well?
So when compared to ANT, Maven definitely does not seem to be the next big thing since it just extends the idea?.
Coming to the control part. I will take some simple examples that I understand and i guess are common with most builds. We have the option to do a clean build which takes time or an incremental build thereby saving lots of time for the developers. We also have targets that enable us to deploy the application(ear) in an exploded format say in weblogic so that an ear does'nt need to be built everytime( building the ear takes time in our case).
Hope Maven does'nt prevent me from doing such things?
Rest assured , i wont trouble you with anymore newbie kind of questions . Before actually hitting one of the tutorials, i just wanted to satisfy my curiosity.
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Originally posted by karthik Guru:
Its realize that you are excited about maven. Would it be possible for you to expand a little more on this. Is it because it is easier to use than Ant?

First off, I'm not a committer to either the Ant project or the Maven project, so I'm not biased toward either build tool. I'm a huge fan of Ant and am becoming a fan of Maven. I don't care which tool you use--I don't get any money or credit for either.
That said, I like Maven largely because I'm able to keep my build files really small. Most of the common build stuff is already predefined in Maven's extensive collection of prepackaged goals (700+). In fact, it's possible to have an extremely simple Maven build file (about a dozen lines at most) that can compile, unit-test, JavaDoc, JAR, WAR, and EAR up your code. Try doing that with only 12 lines of build.xml.
Consider this: In Ant, when you set up your "compile" target, you include a call to the "javac" task. In doing so, you set up the classpath, the source path, the target path, and any other stuff you want to tell javac. In Maven, you do none of this. In fact, you don't even set up a "compile" target. There's already a predefined "java:compile" goal that knows where everything is (because of Maven's imposed project structure).
I'm also a big fan of Maven's repository. The implications of this are huge. Basically, in my project.xml file, I can declare that my project depends on Commons collections version 2.1. From there Maven will take responsibility for obtaining the JAR file (yep, it goes and downloads it for me) and for including that JAR in my classpath (yep...no more classpath hassles).
Writing Ant custom tasks seems to be quite simple. I'm sure Maven also allows us to extend it with plugins. Is it as simple as ANT? and can be easily plugged-in as well?

Indeed, it is possible to extend Maven. In fact, at the project level, that's what the maven.xml file is intended for. If you don't need anything beyond the predefined goals, you won't even need the maven.xml file. At the cross-project level, you can create your own plugin and put them in Maven's plugins directory.

So when compared to ANT, Maven definitely does not seem to be the next big thing since it just extends the idea?.

Exactly! Maven is just an abstraction above Ant. It's not revolutionary as much as it is just a wrapper on Ant.

Coming to the control part. I will take some simple examples that I understand and i guess are common with most builds. We have the option to do a clean build which takes time or an incremental build thereby saving lots of time for the developers. We also have targets that enable us to deploy the application(ear) in an exploded format say in weblogic so that an ear does'nt need to be built everytime( building the ear takes time in our case).
Hope Maven does'nt prevent me from doing such things?

Incremental builds are just as with Ant. It won't build what doesn't need to be built. The only different is that you don't have to write your own "clean" target because there's already a "clean" goal built in.
With regard to the "exploding ear" (whoa...strange visual there): I don't know if Maven comes with a goal to do such a thing or not, but it can't be that hard to write one yourself.
Here's an important thing to understand: Maven goals are composed of nothing more than Ant tasks. The only real difference is that Maven's XML files are also Jelly scripts--meaning you have the ability to do looping and conditional constructs. Other than the Jelly implications, writing a Maven goal is pretty much the same as writing an Ant target. So, if you can do it in Ant, you can also do it in Maven.

Rest assured , i wont trouble you with anymore newbie kind of questions . Before actually hitting one of the tutorials, i just wanted to satisfy my curiosity.

No problem. Maven's great, but I do understand some of the resistance it has faced. The way I see it there are three reasons for resisting Maven: (1) The fundamentals are slightly different than Ant and these differences give the perception that it is more difficult--in actuality, it's much easier once you understand Maven's concepts. (2) Like I said before...Maven isn't for control freaks. If you don't like your directory structure being dictated to you, then you won't like Maven. (3) Some projects are already very married to Ant--switching to Maven isn't impossible, it's just more trouble than it's worth.
Honestly, there are a few misgivings that I have with Maven, but none of them are significant enough to mention here (unless someone asks) and they are probably more of my own ignorance than a limitation of Maven.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Craig, is it ever likely that we will see an "XDoclet for Maven" in the not to distant future?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Originally posted by Barry Gaunt:
Craig, is it ever likely that we will see an "XDoclet for Maven" in the not to distant future?

Believe me...I've been pondering this lately.
I am using XDoclet with Maven and it's working great. The catch is that there is no built-in goals for XDoclet, so you have to write your own.
I suppose that there could be an XDoclet plugin. The problem is that there's so much stuff that you can generate with XDoclet. You'd have to write an XDoclet plugin with several goals. Perhaps goals such as "xdoclet:homeinterface", "xdoclet:hibernatemapping", and "xdoclet:mbeaninterface" (as well as several dozen others). Again, I've been giving this a lot of thought in the past few days...if nobody beats me to it, maybe I'll write up such a plugin someday.
But for now I've taken the simple approach of creating a pregoal for "java:compile" that uses XDoclet tasks and subtasks. I'd post it here for everyone to enjoy, but I don't have that code on this computer. Maybe later I'll post it if anyone's interested.
[ January 15, 2004: Message edited by: Craig Walls ]
[ January 15, 2004: Message edited by: Craig Walls ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Thanks Craig, I'll have to take a look at Maven over the weekend.
-Barry
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Originally posted by Barry Gaunt:
Thanks Craig, I'll have to take a look at Maven over the weekend.
-Barry

same here thanks craig. Please do post the code that you are referring to. I find my build file to be quite long! Let me see what i can do with Maven. If am able to integrate our structure with Maven and if the resulting project.xml indeed turns to be small, I owe you a big thanks for encouraging us to try Maven!
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Originally posted by karthik Guru:
I owe you a big thanks for encouraging us to try Maven!

Hold your applause until you've tried it. As I stated, some people try Maven and hate it. My only advice to you is to not give up too quickly. Maven's core concepts are different than Ant's and it takes a little time to get used to them. To be honest, I tried and gave up on Maven a half-dozen times or so before it finally hit me. Once it did, it made lots of sense.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Should i move my builds from ANT to Maven?
 
Similar Threads
Confusion with "run-as" security identity
Keeping tests in sync
IDE vs text editors for coding
Loading resources from jar using maven and ant
how to reduce the deploy time of ejbdeploy command