2

我们正在考虑将我们的构建系统从 Ant+Ivy 迁移到其他东西,而 Buildr 就是其中一种可能性。但是,它似乎不支持开箱即用的 Ivy,我们不希望将我们内部的 Ivy 存储库和 ivy.xml 文件转换为 Maven 和 POM。

我看到有一个带有 Buildr 扩展的ivy4r项目,这似乎是整合两者的唯一方法。但是,该项目在相当长的一段时间内没有新的开发,并且没有可靠的示例或文档。

有没有人有 Buildr+Ivy 集成的示例或 ivy4r 的简单示例?我不是 Ruby 开发人员,所以语法对我来说是陌生的,如果没有一些示例代码,恐怕很难完成这项工作。

4

1 回答 1

0

以下是buildrivy4r. 评论应该清楚地说明会发生什么。

要记住的最重要的事情是,这些post_resolve块仅在构建已经运行时执行。如果您设置了导致常春藤解析的任务依赖关系,那就太晚了。

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
于 2014-01-16T08:33:35.233 回答