我们需要在编译步骤之后运行一些代码。 在编译步骤之后使事情变得容易:
compile in Compile <<= (compile in Compile) map{x=> // post-compile work doFoo() x }但是你如何在新编译的代码中运行一些东西?
关于场景的更多信息:我们在电梯项目中使用较少的css。 我们希望电梯能够在运行时(如果需要)更少地编译成css来帮助dev,但是在构建期间,在测试等运行之前,使用相同的代码产生更少的代码。 less-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?
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.
最满意答案
您可以像这样使用triggeredBy方法:
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)在任何编译之后,这将使用应用程序的运行时类路径实例化刚刚编译的类。
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.
更多推荐
发布评论