gpt4 book ai didi

编译后SBT在项目中运行代码

转载 作者:行者123 更新时间:2023-12-05 00:27:00 25 4
gpt4 key购买 nike

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

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

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

关于场景的更多信息:我们在提升项目中使用较少的 css。我们希望提升在运行中(如果需要)将较少的编译成 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)

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

关于编译后SBT在项目中运行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21434535/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com