Is there a plugin for sbt available which automatically installs JRuby and adds some hooks to automatically run scripts at certain points (e.g. before compilation).
Background: For a (lift) project, I want to use sass, or more specifically, compass as a tool for generating the css. A Java or Scala clone of sass would not be enough, unfortunately.
Of course, It wouldn’t be a problem at all to just generate the css manually and then put both inside the repository and no-one ever needs to care about it.
On the other hand, to ease development on several systems, I’d rather have a clear dependency inside sbt which simply does the work.
Is there any way to achieve this?
Or generally: Is there a way to run JRuby scripts from inside Scala?Edit Added maven-2 to the tags.开发者_JS百科 Maybe there is a maven repo for JRuby which allows me to deliver and use it somehow.
While it's perhaps not the most elegant solution, you can always call external scripts using the Process support in SBT.
import sbt._
import Process._
class Project(info: ProjectInfo) extends DefaultProject(info) {
lazy val runSomething = task {
"ruby somescript.rb" ! log
None
}
}
There's a bit more info about the external process support available here: http://code.google.com/p/simple-build-tool/wiki/Process
Try my sbt plugin from github. It's very bare-bones for now, but it should download the jruby jar and allow you to call a .rb file before compiling.
The guts of the plugin are really simple:
import sbt._
object SbtJRuby extends Plugin {
object SbtJRubySettings {
lazy val settings = Seq(Keys.commands += jirb, tx, jrubyFile := file("fnord.rb"))
}
def jirb = Command.args("jirb", "<launch jirb>") { (state, args) =>
org.jruby.Main.main(List("-S", "jirb").toArray[String])
state
}
val jruby = TaskKey[Unit]("jruby", "run a jruby file")
val jrubyFile = SettingKey[File]("jruby-file", "path to file to run with JRuby")
val tx = jruby <<= (jrubyFile, Keys.baseDirectory) map { (f: File, b: File) =>
val rb = (b / f.toString).toString
// println("jruby with " + rb)
org.jruby.Main.main(List(rb).toArray[String])
}
}
Really all it's doing is calling the jruby jar file with the name of the rb file you've passed in. And of course adding jruby itself as a managed dependency:
libraryDependencies ++= Seq(
"org.jruby" % "jruby-complete" % "1.6.5"
)
It also adds a "jirb" command to the Scala console that puts you into a jirb session.
精彩评论