编译后SBT在项目中运行代码 [英] SBT run code in project after compile

查看:37
本文介绍了编译后SBT在项目中运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要在编译步骤之后运行一些代码.在编译步骤之后让事情发生似乎很容易:

we need to run some code after the compile step. Making things happen after the compile step seems easy:

compile in Compile <<= (compile in Compile) map{x=>
    // post-compile work
    doFoo()
    x
}

但是你如何在新编译的代码中运行一些东西?

but how do you run something in the freshly compiled code?

有关场景的更多信息:我们在提升项目中使用较少的 css.我们希望提升在运行中(如果需要)将较少的编译成 css 以帮助开发人员,但在构建期间、测试等运行之前使用相同的代码生成较少的代码.less-sbt 可能会有所帮助,但我们对一般如何解决这个问题很感兴趣.

More info on the scenario: we are using less for css in a lift project. We wanted lift to compile less into css on the fly (if needed) to help dev, but produce less using the same code, during the build, before tests etc run. less-sbt may help but we are interested in how to solve this generally.

推荐答案

你可以像这样使用 triggerBy 方法:

You can use the triggeredBy method like this:

yourTask <<= (fullClasspath in Runtime) map {classpath =>
  val loader: ClassLoader = ClasspathUtilities.toLoader(classpath.map(_.data).map(_.getAbsoluteFile))
  loader.loadClass("your.class.Here").newInstance()
} triggeredBy(compile in Compile)

这将在任何编译后使用应用程序的运行时类路径实例化刚刚编译的类.

This will instantiate your class that has just been compiled, using the runtime classpath for your application, after any compile.

这篇关于编译后SBT在项目中运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆