jruby 的 Sbt 插件

发布于 2024-10-04 19:01:18 字数 516 浏览 5 评论 0原文

是否有一个 sbt 插件可以自动安装 JRuby 并添加一些钩子以在某些点(例如在编译之前)自动运行脚本。

背景:对于(提升)项目,我想使用 sass,或更具体地说,compass 作为生成 css 的工具。不幸的是,sass 的 Java 或 Scala 克隆还不够。

当然,手动生成 css 然后将它们放入存储库中根本不会有问题,而且没人需要关心它。

另一方面,为了简化多个系统上的开发,我宁愿在 sbt 内部有一个明确的依赖关系,它可以简单地完成工作。

有什么办法可以实现这一点吗?
或者一般来说:有没有办法从 Scala 内部运行 JRuby 脚本?

编辑 将 maven-2 添加到标签中。也许有一个 JRuby 的 Maven 存储库,它允许我以某种方式交付和使用它。

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. Maybe there is a maven repo for JRuby which allows me to deliver and use it somehow.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦在深巷 2024-10-11 19:01:18

虽然它可能不是最优雅的解决方案,但您始终可以使用 SBT 中的进程支持来调用外部脚本。

import sbt._
import Process._

class Project(info: ProjectInfo) extends DefaultProject(info) {
  lazy val runSomething = task {
    "ruby somescript.rb" ! log
    None
  }
}

这里提供了有关外部流程支持的更多信息:http:// code.google.com/p/simple-build-tool/wiki/Process

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

但可醉心 2024-10-11 19:01:18

尝试我来自 github 的 sbt 插件。目前它还很简单,但它应该下载 jruby jar 并允许您在编译之前调用 .rb 文件。

该插件的内部结构非常简单:

    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])
      }
    }

实际上,它所做的就是使用您传入的 rb 文件的名称调用 jruby jar 文件。当然,将 jruby 本身添加为托管依赖项:

libraryDependencies ++= Seq(
  "org.jruby" % "jruby-complete" % "1.6.5"
)

它还添加了一个“jirb”将命令发送到 Scala 控制台,使您进入 jiirb 会话。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文