I had a similar problem, wanting to publish a project into a private maven repo. The plugin I have been working on, buildr-resolver, can build a POM using Maven's own libraries. It uses all the dependencies pasted to Buildr::Resolver.resolve. Unfortunately, the POM output treats all the dependencies as compile scope. In the near future I'll add the ability for other scopes, test being the big one.

The buidlr-resolver is sorely lacking in the integration with Buildr department, but it does work. You can install it via rubygems. Here is an example buildfile that writes a pom.xml:

require 'buildr/resolver'

Java.load
deps = ['org.apache.activemq:activemq-spring:jar:5.4.2']
deps =  Buildr::Resolver.resolve( deps )

define 'example' do
    project.version = '0.1'
    compile.with deps
    package :jar
end

task :pom do |t|
  # notation of the project model, location to write to
  Buildr::Resolver.write_pom( "com.slackworks:buildr-resolver:jar:0.1, 
'pom.xml' )
end


buildr pom will create the pom.xml now

thanks,
Michael


On 03/10/2011 07:07 AM, Marc-André Laverdière wrote:
Hello everyone,

I am not strong enough in Ruby to create an extension, but I thought
it would be trivial for someone on the mailing list

Here is the code that converts artifacts into a pom file:

     Mustache.template_file = 'pomtemplate.mustard'
     pom = Mustache.new
     pom[:group] = project.group
     pom[:artifact] =  project.id
     pom[:version] = project.version
     pom[:dependencies] = alldeps.map{|x| Artifact.to_hash(x)}
     File.new(pom_file, "rw").write pom.render
     puts "Generated POM file in " + pom_file

The mustache template is as follows

<?xml version="1.0" encoding="UTF-8"?>
<project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>{{group}}</groupId>
   <artifactId>{{artifact}}</artifactId>
   <version>{{version}}</version>

   <dependencies>
{{#dependencies}}
     <dependency>
       <groupId>{{group}}</groupId>
       <artifactId>{{id}}</artifactId>
       <version>{{version}}</version>
     </dependency>
{{/dependencies}}
   </dependencies>
</project>:

I think it would be very useful to have POMs with the deps. I am
working with a in-house lib, and it breaks a lot of buildr files
whenever we update one dependency.
When could we have it in production?

Regards,

Marc-André LAVERDIÈRE
"Perseverance must finish its work so that you may be mature and
complete, not lacking anything." -James 1:4
http://asimplediscipleslife.blogspot.com/
mlaverd.theunixplace.com

Reply via email to