2

We are looking at migrating our build system from Ant+Ivy to something else, and Buildr is one of the possibilities. However, it doesn't appear to support Ivy out of the box, and we have no desire to convert our in-house Ivy repo and ivy.xml files to Maven and POMs.

I see there is an ivy4r project with a Buildr extension which appears to be the only way to integrate the two. However, the project hasn't had new development in quite some time, and there are no solid examples or documentation.

Does anyone have a sample of Buildr+Ivy integration or a simple example of ivy4r? I'm not a Ruby developer so the syntax is foreign to me, and without some sample code I'm afraid it will be very difficult to make this work.

Ryan Nelson
  • 4,466
  • 5
  • 29
  • 45

1 Answers1

0

The following is a small buildfile that shows buildr together with ivy4r. The comments should make it clear what happens.

The most important thing to remember is that the post_resolve blocks are only executed while the build is already running. If you set up your task dependencies that cause ivy resolving in their, it is too late.

require 'buildr/ivy_extension'

repositories.remote << "http://repo1.maven.org/maven2"
THIS_VERSION = 1.0

define 'my-app', :version => THIS_VERSION do
  # Tell ivy4r to add task dependencies to the compile and test tasks.
  # These tasks will cause ivy to resolve the needed artefacts.
  ivy.compile :conf => 'default', :type => 'jar'
  ivy.test :conf => 'test', :type => 'jar'

  # Declare package tasks so that buildr sets up their dependencies.
  jar = package :jar
  zip = package :zip

  # During the build, at some point ivy will resolve because of the
  # task dependencies set up above.
  # After ivy has resolved, the post_resolve blocks will be run.
  ivy.post_resolve do |ivy|
    # Now that ivy has resolved, get a list of the jar artefacts.
    deps = ivy.deps :conf => 'default', :type => 'jar'

    # Do something interesting with the artefacts.
    # -> e.g. put them in the manifest of the main jar
    jar.with :manifest => manifest.merge({
        'Main-Class' => 'Main',
        'Class-Path' => deps.map { |f| "#{File.basename(f)}" }.join(', '),
    })
    # -> package the app as a zip, including also those artefacts
    # This results in a main.jar that specifies its own class path
    # and can be run by double-clicking or just java -jar main.jar
    zip.path("#{id}-#{version}").tap do |p|
      p.include jar, :as => 'main.jar'
      p.include deps
    end
  end
end
jackrabbit
  • 5,525
  • 1
  • 27
  • 38