我有一个在 Play 2.1.1 上运行的 Play 项目。
我想定义一个单独且不同的任务来仅打包我的 Play 项目中的特定包(例如,仅模型包)。我不想覆盖当前的 package
任务,因为我想保留它们的行为。
我如何根据当前package
任务创建自定义任务?
我看过Custom Settings and Tasks在 SBT 文档中,但这些示例相当简单,并且没有给出任何使用 SBT 库的示例。
最佳答案
我想提出一种方法 custom configuration .
以下是示例项目的 build.sbt
:
lazy val CustomPackage = config("custompackage") extend(Compile) describedAs("Custom package configuration")
packageBin in CustomPackage := {
val log = streams.value.log
import log._
info("""Returning custom packaging artifact, i.e. file(".")""")
file(".")
}
lazy val root = project in file(".") overrideConfigs (CustomPackage)
在上面的构建配置中,有一个 custompackage
配置,用于确定设置和任务的范围。作为如何更改 packageBin
任务行为的示例,此范围内有一个(重新)定义。最后一行将自定义配置添加到项目中。
当您运行 SBT shell (sbt
) 时,您会注意到真正的 packageBin
任务在 custompackage
范围内发生变化时未受影响。默认情况下,您处于Compile
配置中。要更改它,您需要使用扩展语法在另一个配置中执行任务。
[root]> configuration
[info] compile
[root]> show packageBin
[info] /Users/jacek/sandbox/so/config-package/target/scala-2.10/root_2.10-0.1-SNAPSHOT.jar
[success] Total time: 0 s, completed Feb 8, 2014 2:27:10 PM
当您将配置轴更改为 custompackage
时,任务 packageBin
会发生变化。
[root]> custompackage:configuration
[info] custompackage
[root]> show custompackage:packageBin
[info] Returning custom packaging artifact, i.e. file(".")
[info] .
[success] Total time: 0 s, completed Feb 8, 2014 2:27:20 PM
[root]> custompackage:packageBin
[info] Returning custom packaging artifact, i.e. file(".")
[success] Total time: 0 s, completed Feb 8, 2014 2:27:25 PM
全部在 SBT 0.13.1 下进行测试。
[root]> about
[info] This is sbt 0.13.1
[info] The current project is {file:/Users/jacek/sandbox/so/config-package/}root 0.1-SNAPSHOT
[info] The current project is built against Scala 2.10.3
[info] Available Plugins: com.typesafe.sbt.SbtGit, com.typesafe.sbt.SbtProguard, growl.GrowlingTests, org.sbtidea.SbtIdeaPlugin, np.Plugin, com.timushev.sbt.updates.UpdatesPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.3
关于playframework-2.0 - 如何创建自定义 "package"任务以仅在 SBT 中打包特定包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21615592/