在sbt-native-packager中扩展“通用”配置

时间:2015-10-26 13:49:03

标签: scala sbt sbt-native-packager

我正在使用sbt 0.13.8和sbt-native-packager 1.0.3。

我想用不同的java选项设置开发和生产包装配置。我们的想法是通过UniversalPluguin中的sbt-native-packager : "universal:packageZipTarball"创建一个包tarball。我也在使用“JavaServerAppPackaging”原型。

我试过这个Build.scala

import sbt._
import Keys._
import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport._
import com.typesafe.sbt.packager.archetypes.JavaServerAppPackaging

object Build extends Build {

  lazy val commonSettings: Seq[Setting[_]] = Seq(
    scalaVersion := "2.11.7",
    crossScalaVersions := Seq("2.11.7"),
    scalacOptions in Compile ++= Seq( "-unchecked", "-feature", "-language:postfixOps", "-deprecation" )
  )

  lazy val devConfig = config("dev") extend Universal
  lazy val prodConfig = config("prod") extend Universal

  lazy val root = (project in file("."))
    .settings(commonSettings : _*)
    .enablePlugins(JavaServerAppPackaging)
    .configs(devConfig, prodConfig)
    .settings(
      javaOptions in devConfig ++= Seq(
        // -J params will be added as jvm parameters
        "-J-Xmx384m",
        "-J-Xss512k"),
      javaOptions in prodConfig ++= Seq(
        // -J params will be added as jvm parameters
        "-J-Xmx384m",
        "-J-Xss740k")
    )
}

通过该设置,SBT始终失败:

Error:Error while importing SBT project:
...
at sbt.Classpaths$$anonfun$updateTask$1.apply(Defaults.scala:1310)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:235)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbtConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[error] java.text.ParseException: unknown configuration 'universal'. It is extended by dev in null
[error] Use 'last' for the full log.

See complete log in /Users/ivan/Library/Logs/IdeaIC14/sbt.last.log

我支持使用sbt命令“dev:packageZipTarball”创建两个打包的tarball进行开发,以及使用不同jvm选项的“prod:packageZipTarball”生成。

为什么我不能使用自定义配置扩展“universal”配置以实现该方法或替代方法的任何想法?

1 个答案:

答案 0 :(得分:2)

我强烈建议不要扩展配置。行为不是预期的行为。实现不同构建配置的最佳方法是为每个配置创建子模块

请参阅this answer,其中更详细地解释了如何创建具有不同配置的子项目。