2012-04-20 25 views
2

我們正在考慮將我們的構建系統從Ant + Ivy遷移到其他方面,Buildr是其中一種可能性。但是,它似乎並不支持Ivy,我們也不希望將我們的內部常青藤repo和ivy.xml文件轉換爲Maven和POM。與常春藤一起使用Buildr的例子?

我看到有一個ivy4r項目與一個Buildr擴展似乎是唯一的方法來整合這兩者。然而,該項目在相當一段時間內還沒有新的發展,也沒有可靠的例子或文件。

有沒有人有Buildr + Ivy集成的示例或ivy4r的簡單示例?我不是Ruby開發人員,所以語法對我來說是陌生的,沒有一些示例代碼,恐怕很難做到這一點。

回答

0

以下是顯示buildr連同ivy4r的小構建文件。評論應該清楚發生了什麼。

最重要的是要記住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