Sunday, September 27, 2009

Introducing Maven Trap - the honey pot for Maven malcontents

For far too many years, Maven 2 has dominated my builds, and I've sat idly by, taking what they've given, meekly replying, "Thank you sir, can I have some more?" I've watched my builds break apart on unmodified code or just hang, I've nearly drown fighting the torrent of jumbled output trying to find the lone test failure, and I've lost my sanity wading through huge XML build files trying to understand why my build is downloading the internet.

Sure, there have been moments of resistance, like when I created a fork of Maven to add features like parallel downloading of artifacts, but the effort in maintaining a fork is too high when, honestly, I'd rather be doing just about anything than hacking build systems. Still, the revolutionary fire never died, despite not having a sustainable outlet.

Like the scrappy fighter that keeps bouncing back after a huge left hook, I'm back, but this time, looking for victory by treating Maven like the unpredictable wild animal it can be. Instead of forking Maven, a fellow Atlassian Sam Le Berrigaud and I have put it in its cage by wrapping the executable with an interceptor framework, allowing modules to control how Maven gets executed and what happens after it gives up the ghost.

Maven Trap is this executable interception framework and three modules:
  • Console Colorization - Pages of white or green text is hard to read and makes it easy for critical errors to slip by. This module transforms output into ANSI colorized text to make it easier to see errors and other key events.

  • Always Offline - A build system should not connect the network unless you explicitly give it permission. This module inverts the meaning of the "-o" flag to make the default offline, only to be enabled via the "-o" flag.

  • YAML POM - While XML is great for programs, it sucks for humans. This module automatically converts your XML pom.xml file into a YAML-formatted pom.yml for either read-only or editable usage.
Since Maven Trap treats Maven as an opaque black box, what it can do is limited, however, it provides low-risk integration points that can be extended fairly easily and should work with most any version of Maven. Each module can be enabled by setting a unique environment variable, giving you full control over which features you want without modifying your Maven installation.

No announcement is complete without a screenshot, so here is all three modules enabled on simple project:



We use this in the Atlassian Plugin SDK, as we include our own customized installation of Maven to try to reduce the Maven hassles that our development community continually faces. If you too are fed up with how Maven is always accessing the internet, produces heaps of unmanageable output, or uses obtuse XML configuration, give Maven Trap a go, or better yet, join GitHub and fork it for full control.

20 comments:

  1. I just cloned the git repos and cannot build your project. I get the following missing artifact :



    [INFO] Failed to resolve artifact.
    1) org.twdata.maven:maven-yamlpom-plugin:jar:0.5
    Path to dependency:
    1) org.twdata.maven.trap:yamlpom:jar:0.6-SNAPSHOT
    2) org.twdata.maven:maven-yamlpom-plugin:jar:0.5



    Is there a 0.5 branch ?

    ReplyDelete
  2. Are you running from the root of the repository? The jar in question is in my twdata-m2-repository, which is defined in the parent pom. Therefore, you should see something like this:
    Downloading: http://twdata-m2-repository.googlecode.com/svn//org/twdata/maven/maven-yamlpom-plugin/0.5/maven-yamlpom-plugin-0.5.pom
    9K downloaded (maven-yamlpom-plugin-0.5.pom)
    Downloading: http://twdata-m2-repository.googlecode.com/svn//org/twdata/maven/maven-yamlpom-plugin/0.5/maven-yamlpom-plugin-0.5.jar
    226K downloaded (maven-yamlpom-plugin-0.5.jar)

    ReplyDelete
  3. Alternatively, you can download the jar from GitHub.

    ReplyDelete
  4. I issued "mvn clean install" from the root of the repos yes.

    Downloading the jar from github ...

    ReplyDelete
  5. Forks are good for the community, because they create competition. A good vision statement, well defined goals and policies are needed to start a successful fork. (A lot of coding after that ;-)

    ReplyDelete
  6. @ali65, totally agree, however, that also implies a lot of work :) Github makes it easier to quickly fork and track forks, but still, it is work. Also, I had some issues with my Maven fork in that projects that used the enforcer plugin to require a certain version of Maven would fail, as 2.0.9 != 2.0.9-db1. Finally, full access to the source, as you get a fork, can be a curse just as much as a blessing....

    ReplyDelete
  7. Well done - the color output is particularly useful.

    But it does, once again, show what an unmaintainable mess of undocumented plexus that maven is, that these things can't be fixed in the core.

    ReplyDelete
  8. Good for you, fighting the fight. Weaker-willed individuals might have ditched the whole tool ;-)

    ~Matt

    ReplyDelete
  9. Hi
    cant seem to get this to work.
    I followed the steps

    1. Copy maven-trap-0.5.jar file to M2_HOME/boot
    2. Edit the M2_HOME/bin/mvn script and change the last line from: ....

    3. M2_HOME system variable environment set
    MAVEN_COLOR
    MAVEN_ALWAYS_OFFLINE
    MAVEN_YAMLPOM

    apache-maven-2.2.0
    windows XP

    any ideas.

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Hey 'anonymous', you might have to update you 'mvn.bat' file on windows (and not the 'mvn' one). I'm afraid neither Don nor I have had a look into that.
    Feel free to contribute back to the github project once you get it working ;-)

    ReplyDelete
  12. I've updated mvn.bat file and added the line

    set %CLASSWORLDS_JAR%=%CLASSWORLDS_JAR%;"%M2_HOME%"\boot\maven-trap-0.5.jar

    Then relaced class with org.twdata.maven.trap.Dispatcher

    After setting MAVEN_COLOR variable
    the output displays the following ( no color )

    <-[m[info]......

    ReplyDelete
  13. Don, I'm in a conversation with a fellow colleague on repeatable builds with maven.

    I have been always doing this by freezing the parent POM and setting the remote repo to an internal one.

    What is your approach to this right now? Do you use one of your previous forks or use the stable maven release?

    Cheers,
    Gergő

    ReplyDelete
  14. Don, have you approached the Maven guys to get your (not suck) list put in JIRA? The resolution to Maven problems shouldn't be run it again. We pass these secrets around in forum posts and such. It seems silly. Parallel http downloads seems perfect. Machines can handle this now. I don't think that we're using potato linux for build boxes anymore.

    ReplyDelete
  15. @Gergely Sure, setting all the versions goes a long ways, but sometimes, you really do need snapshots. You'd be surprised how little you really need Maven to be online

    @David Parallel downloads made it into Maven 2.1 and makes quite a difference. Any core Maven changes I've made I've created JIRA issues for. Maven Trap, however, is an example of building tools on top of Maven where you don't need to modify core. Talking with Jason, it will hopefully be better in 3.0, but then again, all problems are always fixed in the next version :)

    ReplyDelete
  16. Java is amongst one of the most robust platform for programming. Java development gives Java Developers the way to
    develop complex applications.

    ReplyDelete
  17. Hello everyone.
    I am developing a Honeypot System using Java for presenting it at my college as my final year project. But I can't make out something nice out of it. Can anyone help me out by providing the code for it.
    My email address is
    sirambrish@gmail.com

    ReplyDelete
  18. Sun Java is one of the most flexible platform for application development Sun Java development gives the way to develop complex applicaton development.

    ReplyDelete
  19. When you’re getting ready to choose sunglasses, recently, there are wholesale oakley sunglasses. I highly

    recommend that you spend some time looking at these oakley sunglasses.

    ReplyDelete
  20. If you want to cause a sensation, wearing Oakley is a great way to start as it is a brand that catches the eye of most people.Not only does wearing a pair of Oakley sunglasses set you apart from the fake oakley sunglasses they also offer great protection from the sun, which really is of course the primary goal! Oakley crosshair sunglasses, like so many products in the Oakley range are able to offer 100% UV filtering protection, making them the perfect pair of sunglasses for all consumers. A cheaper pair of sunglasses may have a smaller hit on the wallet but if they do not provide adequate protection to the eyes, they are not really worth wearing.Another benefit of buying into the Oakley brand is that they are very reliable. Oakley is very proud of their quality and as the company proudly states,

    ReplyDelete