Learning Maven

I set aside some time this weekend to learn Maven which I continue to hear a lot about and until this weekend knew very little about. I was definitely impressed, I'll be hard pressed to go back to using Ant after seeing the power of Maven. I got started with this article from the TheServerSide.com: Maven Magic.

After working with it a bit, the main areas I hope Maven will improve over time are:

  • Documentation, primarily better docs for the plugins.
  • A downloadable version with binaries and docs. Since I learned it where I only had a dialup connection I found it frustrating to have to dialup everytime I wanted to look for some basic information.
  • Some packages on ibiblio are out of date so I had to use my local repository.

The things I really like about it are:

  • Dependency management, amazing!
  • Plugins plugins plugins plugins!
  • Sensible build defaults for most types of projects.
  • Great Ant integration and support if I need more control over the build process.
  • Nice reporting system for continuous integration build processes.

Here was my one road block while learning Maven. I was missing a jar that one of unit tests required at runtime and here's the output I got when running maven -X test:

BUILD FAILED
File...... C:\Documents and Settings\thuss\.maven\cache
\maven-test-plugin-1.6.2\
plugin.jelly
Element... junit
Line...... 133
Column.... 41
java.lang.NoClassDefFoundError
com.werken.werkz.UnattainableGoalException: Unable to 
obtain goal [test:test] -- C:\Documents and Settings
\thuss\.maven\cache\maven-test-plugin-1.6.2\
plugin.jelly:133:41:  java.lang.NoClassDefFoundError
        at com.werken.werkz.Goal.fire(Goal.java:646)
 	...

Any idea what class is missing based on the above? Me neither! I spent almost an hour searching forums and tearing my hair out until I finally tried setting the property maven.junit.fork=true in my project.properties file. Then JUnits log messages started to show on STDOUT so I could see that I had forgotten the hibernate jar in my dependencies (which was only a runtime dependency since I'm using the spring-orm support). Anyhow, there's probably a maven parameter I could set to show logging messages while running the test goal but I couldn't find it and maven -X was no help. One of the main goals of TDD is that the build process and unit tests will tell you what's broken so you can refactor with confidence. Kind of ironic that one of my unit tests was simply missing a runtime dependency and maven couldn't give me a better error message.

That minor frustration aside, Maven is a great tool!

This entry was posted in Java. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *