• Home
  • RSS Feed
  • Log in

Using Groovy to keep your Maven and Fitnesse dependencies in sync
Posted by Erik Pragt around lunchtime: July 29th, 2008

The problem

What if you're working with Maven, where you've got all your dependencies nicely organised, and now you decide to use any other piece of 'classpath-aware' software, like Fitnesse. The chances are that you'll need to use the same classpath in Fitnesse as in Maven. A possible solution could be to maintain it by hand, but why not write a very small script for it to do it for you? My (very very very!) basic solution is to use a Groovy, because it's easy to write, easy to read, and easy to use!

The solution

 
def pom = new XmlSlurper().parse("pom.xml")
 
pom.dependencies.dependency.each { dependency ->
        println "!path \${mavenRepo}/${dependency.groupId}/${dependency.artifact
Id}/${dependency.version}/${dependency.artifactId}-${dependency.version}.jar"
}
 

Et voila: a very small script to keep track of the Maven dependencies and export them in a format which is suiteable for Fitnesse. Mind the ${maveRepo} though: it's the name of a system property which has been supplied in the run.sh when starting Fitnesse, and points to your Maven repository (which is ${USER}/.m2/repository)

Well, I hope will make your life a little easier, and ofcourse you can do all kinds of nifty things with it, like turning it into a Maven plugin or something.........

  • Share/Bookmark

Tags: fitnesse, Groovy, Maven, script
Filed under Groovy, Maven, fitnesse | 6 Comments »



6 Responses to “Using Groovy to keep your Maven and Fitnesse dependencies in sync”



    Age Says:
    Posted at: July 29, 2008 at 2:48 pm

    What about transitive dependencies and parent POMs ? When you’re simply slurping the xml, you won’t get the transitive and inherited dependencies so your fitnesse classpath might still cause problems.

    I think Maven2 has support for embedding so maybe you could use that part of maven to read the POM.



    Nanne Says:
    Posted at: July 29, 2008 at 11:10 pm

    What about using the manifest for this? Just include the depended jars in your fitnesse project jar manifest.



    Silvester Van der Bijl Says:
    Posted at: July 30, 2008 at 7:23 am

    Hi Erik, thanks for the snippet. Like Age said we need transitive dependencies! Any change of a plugin version for Maven?



    Erik Pragt Says:
    Posted at: July 30, 2008 at 4:30 pm

    @Age: this is not the holy Grails ofcourse! It cannot even handle variables in versions, which some people like to declare. If you want to expand it to handle transitive dependencies (seems quite important) and parent poms (IMO, less import: just run the script twice), go ahead. I’m curious to see what you can come up with. Maybe ITR idea?

    @Nanne: I didn’t think about using the Manifest, but it also has some complications, for example when having an executable Jar with all dependencies extracted in the executable jar. The Manifest won’t contain the dependencies then.

    @Silvester: Ofcourse, when the sun stop shining, days will last 10 hours longer, etc, etc ;) . In other words: those chances are very slim!



    ehsavoie Says:
    Posted at: July 31, 2008 at 7:55 am

    We had a similar problem. We simply created a Maven plugin to getthe classpaths (test,compile, etc.) and construct the command line before launching our external program, treating dependecies the maven way.

    I don’t think I still have the code :o (( because it was so simple we just trashed it when we didn’t need it anymore. :o (
    Emmanuel



    Using FitNesse with the Maven 2 classpath | Xebia Blog Says:
    Posted at: December 16, 2008 at 10:23 am

    [...] for a solution, the first hit that I got which addresses this problem is a blog by my fellow Xebian Erik Pragt. A drawback of his approach is that it does not handle transitive dependencies. Therefore, I found [...]



Leave a Reply

Click here to cancel reply.

Deployment automation for Java application running on Websphere, WebLogic and JBoss

Archives

  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009

Xebia Sites

  • Xebia Corporate
  • Xebia France
  • Xebia India

Categories

  • Java (282)
  • Agile (109)
  • General (50)
  • Testing (42)
  • Performance (42)
  • Hibernate (36)
  • Scrum (33)
  • Podcast (31)
  • Architecture (31)
  • Spring (28)
  • SOA (24)
  • Maven (22)
  • Project Management (22)
  • Middleware (23)
    • Deployment (14)
  • Flex (17)
  • JPA (17)
  • Eclipse (15)
  • Xebia Labs (15)
  • Quality Assurance (14)

Tag Cloud

    Poppendieck Functional Programming Agile Awareness Workshop Xebia Performance Java Hibernate Closures Agile SOA Scala Introduction to Agile qcon Lean Groovy Architecture esb Spring Testing Semantic Web Ajax JavaOne Grails Scrum Maven IntelliJ XML product owner Seam fitnesse