Bundler and Maven living in harmony?
Monday, April 18, 2011
I prefer to run my Ruby apps on the JVM. This preference is due in part to the fact that the JVM gives me access to some excellent libraries - Akka in particular.
But I prefer to keep things strictly Ruby when it comes time to include those libraries in my project. That is to say, I love what Maven does for me, but I don't wan't to use it.
If the Bundler team chooses to accept my contribution, I'm sure we can agree on a better interface.
While my addition to Bundler "works" - it is not very powerful. For one, it does not download the dependencies of the Maven artifacts included in the Gemfile. They have to be specified manually.
I started down the path of parsing the dependencies out of the pom file, and even looking into parent pom files for more details (like properties and version configuration). But very quickly it began to look as though I was re-writing the Maven pom parsing library - because I was!
There are only two ways to properly complete this. This first: rewrite the Maven pom parser in Ruby. And two: use Maven via Bundler.
The first option is out - too much work, and too fragile.
The best way to implement the second option is to require that Maven be installed on the machine running Bundler. This way, my Bundler addition could just call out to `mvn` on the command line. There are several advantages to this, including the ability to use the .m2/repository directory, and picking up all the Maven settings, and repository configurations.
But I need some reassurance from the Bundler team before moving forward.
But I prefer to keep things strictly Ruby when it comes time to include those libraries in my project. That is to say, I love what Maven does for me, but I don't wan't to use it.
That is why I decided to create a Maven integration for Bundler. As it works now, the API is kind of clunky - but that is just to avoid dorking with Bundler too much.
Here is a link to the project: https://github.com/jkutner/bundler
Here is a link to the project: https://github.com/jkutner/bundler
If the Bundler team chooses to accept my contribution, I'm sure we can agree on a better interface.
While my addition to Bundler "works" - it is not very powerful. For one, it does not download the dependencies of the Maven artifacts included in the Gemfile. They have to be specified manually.
I started down the path of parsing the dependencies out of the pom file, and even looking into parent pom files for more details (like properties and version configuration). But very quickly it began to look as though I was re-writing the Maven pom parsing library - because I was!
There are only two ways to properly complete this. This first: rewrite the Maven pom parser in Ruby. And two: use Maven via Bundler.
The first option is out - too much work, and too fragile.
The best way to implement the second option is to require that Maven be installed on the machine running Bundler. This way, my Bundler addition could just call out to `mvn` on the command line. There are several advantages to this, including the ability to use the .m2/repository directory, and picking up all the Maven settings, and repository configurations.
But I need some reassurance from the Bundler team before moving forward.
jruby-maven-plugins
There is the jruby-maven-plugins project. But I believe this solves a very different problem than the one I'm working on. If I were trying to convert my Gemfile into a pom.xml, then I could pretty much generate the XML and hand it off to Maven. But thats not what I want to do. I want to continue using Bundler. So really, I'm doing quite the opposite of the jruby-maven-plugin (I might be wrong about this, so please explain if I am).
UPDATE (4/19/2011):
So kristian's jruby-maven-plugins are not what I need - but the ruby-maven gem is. I'm going to investigate using this as the backbone of my Maven source class.
specs
In working with the Bundler repository, I also came across the problem of not being able to run my maven_spec.rb. The Bundler specs only run on C Ruby (because of a mkmf dependency). And my specs won't run on C Ruby because they require JRuby - its a catch 22. I believe there is a way to create platform specific specs - I suppose this will be necessary.
In working with the Bundler repository, I also came across the problem of not being able to run my maven_spec.rb. The Bundler specs only run on C Ruby (because of a mkmf dependency). And my specs won't run on C Ruby because they require JRuby - its a catch 22. I believe there is a way to create platform specific specs - I suppose this will be necessary.
I welcome ANY feedback or criticism. Thanks.

2 Comments:
This is very neat, installing maven artifacts from bundler will be really useful. I'm not an expert, but doesn't ruby require maven or the jruby-maven gem to be installed to require maven artifacts anyway? When I follow the instructions at http://blog.mkristian.tk/2011/03/rubygems-maven-support.html, I can get bundler to recognize and require a maven artifact that I've installed with 'gem install', but it seems 'bundle install' doesn't know how to install a maven-based gem. For consistency, it might be good if you used the 'mvn:org.slf4j:slf4j-simple' format for the gem name in the Gemfile rather than have a special maven option.
Maybe you could take a look at how Grails supports Maven or how Grape integrates it in Groovy. Maybe releasing some gem with all required jars may allow you to use some class from Maven or another java library to allow us to get the dependencies without having to depend on external programs which will have some problems and will be platform specific probably.
Post a Comment
<< Home