Maven: Why does it have to be so hard?

Every project I start I try to use Maven. It seems like the right choice but I consistently fail. Every step is hard. It's not just that there are infrastructure hurdles, but the commands are hard, the POM is complex and nothing is easy.

This J bites.

Ok, enough whining. Maven is the right way to manage your build environment simply because it is the only tool that manages your dependencies. This is a simple concept.

We can argue that ant has sufficed for a long time and that is true. So, we can argue that the dependency complexities that we face are actually not that hard since we appear to be able to work it out without another tool, but wouldn't it be great if we could leverage the learning that others have already put into setting up the correct dependencies?

Well I am installing grails, an ant solution, and integrating CXF and Mule. I am facing continuous versioning problems with all the xml/soap/ws etc jars. I am sure that when I have solved this problem, I will promptly forget it and have to solve it all over again for the next project.

I would like to be able to capture the solution in a POM so that I could reuse it even if no one else does.

So, what is step one. Create a maven project. This is so hard. I can't believe they make us do this. No wonder this tool is taking so long to gain acceptance.

mvn archetype:create -DgroupId=com.company.project-DartifactId=project-name-DarchetypeArtifactId=maven-archetype-webapp

Yes, that is the command to create a project, and I didn't even specify all the other version options that they mention. All it does is create this:


It doesn't do much but it does allow us to enforce standards and, when we develope our own archetypes will improve project structure consistency accross the board. This is all good but why do I need to pass in system properties? Who ever heard of a command line interface that makes you declare system properties.

Perhaps it could prompt for the required fields like "grails create-app". Perhaps there should be a web page on the maven site that will help. I had to go through google to find it. Their quick start doesn't even talk about it.

I know, I know, I am whining. I could probably contribute to the project myself, it's open source and all that.

There is an Eclipse and NetBeans plugin that makes life a little easier.

There comees a point when we learn to love the new tool. I just pasted a glob of xml into my POM file because some CXF/Maven web page told me to, saved it, and the maven eclipse plugin promptly downloaded all the jars required to bring a CXF web service up and running. This took me an hour or so the first time. Maven just made my life easier.


And again I am dashed to the jagged rocks of the learning curve. It appears maven doesn't use the JAVA_HOME environment variable to determine the JDK version to use and it is defaulting to JDK 1.3 which is not even installed on my machine. I have annotations so it will not work anyway.

I suppose it makes sense because it is requiring explicit version declarations for all other jars so why not the rt.jar but it is not telling me how to specify it.

This brings up the odd balance in our lives of detail vs default. If I require everything specified I know my build will always be correct. If I allow default selections using JAVA_HOME for example, it may fail but will usually work.

This is why maven is so hard to deal with. Nothing is easy. Specify or die a bloody death and don't expect to block the gushin wound with documentation because even google is lost.


Ok, I found it, System Dependencies

Oh wait, that is wrong, doesn't work and I don't know what it does though it sounded so close. Infact, we want this Compiling-J2SE-5

Man that took another 30 minutes, I almost gave up on Maven again.

I might be back to loving maven again. Once you have run your "mvn package" to create your war file you can run "mvn tomcat:run" which will run tomcat in place from your generated war file. Now that is cool.

Well, while I can't expect maven to solve all my problems, since it's intent is to solve dependency problems I did have that expectation. Silly me.

The CXF xml glob that I pasted to get all the CXF jars and dependencies downloaded apparently missed the SAAJ jars. I expect I will have to find and add these to my project file manually.

I am starting to feel as though I might be starting to understand Maven, even if it isn't doing what I want.


Anonymous said...

LOL! Man this is a funny post. I feel your pain! I almost got the urge to code something to replace Maven. I never got really started on it myself. I seem to do just fine with a handful of ant scripts.. actually, maybe thats the way forward. dependency handling and a selection of ant scripts.. or what do you prefer.. how much should be specified for a project? can you set up some requirements for a maven replacement?


Edward Sumerfield said...

I started a re-write myself, called it JShelf, as in you get jars of a shelf? Even got as far as creating the sourceforge project.

Turns out a CVS repository and a fancy name isn't enough to make stuff happen :-)

I like your idea of seperating dependency management from build process. Maven has all these local and remote repositories that impact the build process when perhaps all they need is a a way to get the correct dependencies into our lib dirs so that we can do our ant builds.

Of coarse gem is a nice solution to this with no build add-ons but then there aren't many build steps in a ruby product anyway.

Friendless said...

I spent months putting maven into our project then years taking it out. It just doesn't do what anyone wants. You say "Maven is the right way to manage your build environment ..." but what evidence do you have for that? What if the tool is more complex than doing the task by hand? Our life has been so much simpler since we went back to using ant.

Edward Sumerfield said...

I say it is the right approach because of the solution it offers. That is not to say that it is capable of supplying those features easily.

I have heard many stores like yours and conversley stories from Maven lovers that think it is the perfect solution.

I guess we all have to work out if it is the right tool for the problem we have.

Dispite the partial success I achieved this weekend I still don't feel able to use Maven for a full project yet. That has to be a testament to its feasability right there.

Perhaps all we need is a JarDownload ant task.

Michael Easter said...

I found Maven v 1.x to be painful.... good ideas but the execution was brutal.

Perhaps Maven v 2.x is better?

Regarding Ant and downloads/dependencies, you may want to check out the Apache Ivy project. I haven't used it but it seems to address the issues within the Ant framework.

Anonymous said...

18 months after you wrote this and I am feeling your pain (with Maven 2). It really is the way to do things, except it doesn't quite work.

Anonymous said...

What on earth are you talking about? Setting up the project is hard? Compared to what? Show me what other single-line commands you're issuing to set up entire Java projects! I've heard a lot of complaints about maven, some valid, some not, but this one is ridiculous. Once you've generated from an archetype twice, it becomes second nature. In fact, in later versions, the command is even simpler: mvn archetype:generate

bbaron said...

Ant is the Perl of the Java universe: there's more than one way to do it. Maven has one (default} way to do it. If that way doesn't work for you, you might be able to coerce maven to your way.

Personally, I'd never want to go back to an ant based project, unless a team guru already has the project's ant system well-oiled and it just works.