6

我的 Play 2.3 应用程序中有一个application.dev.confandapplication.test.conf在我的conf文件夹下,但我不希望它被打包为我的分发的一部分?它有什么权利excludeFilter

4

3 回答 3

5

实际上 lpiepiora 的答案会起作用,但是请注意,过滤mappings in Universal只会application.dev.confconf文件夹中排除,而不是从 jar 本身中排除。

我不知道play框架,但一般来说,如果你有这样的东西:

hello
├── src
│   └── main
│       ├── scala
│       │   └── com.world.hello
│       │       └── Main.scala
│       ├── resources
│       │   ├── application.dev.conf
│       │   └── application.conf

正在做:

mappings in (Universal, ) ++= {
  ((resourceDirectory in Compile).value * "*").get.filterNot(f => f.getName.endsWith(".dev.conf")).map { f =>
    f -> s"conf/${f.name}"
  }
}

将产生以下包结构:

hello/
├── lib
│   └── com.world.hello-1234-SNAPSHOT.jar
├── conf
│   └── application.conf

但是,如果您查看 jar,您会看到您的dev.conf文件仍在其中:

$ unzip -v com.world.hello-1234-SNAPSHOT.jar
Archive:  com.world.hello-1234-SNAPSHOT.jar
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
     371  Defl:N      166  55% 10-01-2018 15:20 36c30a78  META-INF/MANIFEST.MF
       0  Stored        0   0% 10-01-2018 15:20 00000000  com/
       0  Stored        0   0% 10-01-2018 15:20 00000000  com/world/
       0  Stored        0   0% 10-01-2018 15:20 00000000  com/world/hello/
       0  Stored        0   0% 10-01-2018 15:20 00000000  com/world/hello/
   13646  Defl:N     4361  68% 10-01-2018 12:06 7e2dce2f  com/world/hello/Main$.class
     930  Defl:N      445  52% 10-01-2018 13:57 5b180d92  application.conf
     930  Defl:N      445  52% 10-01-2018 13:57 5b180d92  application.dev.conf

这实际上并没有真正的危害,但如果你也想删除它们,这里是答案:How to exclude resources during packaging with SBT but not during testing

mappings in (Compile, packageBin) ~= { _.filter(!_._1.getName.endsWith(".dev.conf")) }
于 2018-10-01T14:24:45.020 回答
3

您可以使用mappings排除这两个文件。

mappings in Universal := {
  val origMappings = (mappings in Universal).value
  origMappings.filterNot { case (_, file) => file.endsWith("application.dev.conf") || file.endsWith("application.test.conf") }
}
于 2014-06-24T06:49:29.630 回答
1

excludeFilter以下内容对您有用吗?

excludeFilter in Universal in unmanagedResources := "application.dev.conf" || "application.test.conf"

(默认情况下,该unmanagedResourceDirectories键是指conf/。)

于 2014-11-02T16:24:25.787 回答