如何创建自定义“包"?任务只能在SBT中打包特定的程序包? [英] How to create custom "package" task to jar up only specific package in SBT?

查看:102
本文介绍了如何创建自定义“包"?任务只能在SBT中打包特定的程序包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 Play 2.1.1 上运行的Play项目.

I have a Play project running on Play 2.1.1.

我想定义一个单独且不同的任务,仅在我的Play项目中打包一个特定的程序包(例如,仅是models程序包).我不想覆盖当前的package任务,因为我想保留它们的行为.

I would like to define a separate and distinct task to jar up only a specific package in my Play project (e.g. just the models package). I do not wish to override the current package tasks as I want to preserve their behaviour.

如何根据当前package任务创建自定义任务?

How would I go about creating a custom task based off of the current package task?

我查看了自定义设置和SBT文档中的任务,但这些示例非常简单,没有提供任何使用SBT库的示例.

I've looked at Custom Settings and Tasks in the SBT documentation but these examples are fairly trivial and don't give any examples that use the SBT library.

推荐答案

我想通过以下是示例项目的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任务行为的一个示例,此作用域中有一个(重新)定义.最后一行将自定义配置添加到项目中.

In the above build configuration, there's custompackage configuration that scopes settings and tasks. As an example of how it can change the behaviour of packageBin task there's a (re)definition in this scope. The last line adds the custom configuration to the project.

当您运行SBT Shell(sbt)时,您会注意到,当真正的packageBin任务在custompackage范围内更改时,它并未受到影响.默认情况下,您处于Compile配置.要对其进行更改,您需要使用扩展语法在另一配置中执行任务.

When you run SBT shell (sbt), you will notice that the real packageBin task is untouched while it changes in custompackage scope. By default, you're in Compile configuration. To change it, you need to use the extended syntax to execute a task in another configuration.

[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会更改.

When you change configuration axis to custompackage the task packageBin changes.

[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 下进行了测试.

All tested under 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

这篇关于如何创建自定义“包"?任务只能在SBT中打包特定的程序包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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