我们需要在编译步骤之后运行一些代码。使事情发生在编译步骤之后似乎很容易:
compile in Compile <<= (compile in Compile) map{x=>
// post-compile work
doFoo()
x
}
但是如何在新编译的代码中运行某些内容?
有关场景的更多信息:我们在Lift项目中对CSS的使用较少。我们希望Lift可以在运行中(如果需要)减少编译为CSS的次数(如果需要),以帮助开发人员,但是在构建期间,测试等运行之前,使用相同的代码可以减少编译次数。less-sbt可能有所帮助,但我们对通常如何解决此问题感兴趣。
您可以使用如下所示的TriggerBy方法:
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)
在进行任何编译之后,这将使用应用程序的运行时类路径实例化刚刚编译的类。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句