scala - 如何排除conf文件夹下的文件进行分发?

标签 scala sbt playframework-2.3

我有一个 application.dev.confapplication.test.conf下我的 conf我的 Play 2.3 应用程序中的文件夹,但我不希望它被打包为我的发行版的一部分?什么是对的excludeFilter为了它?

最佳答案

实际上 lpiepiora 的回答可以解决问题,但是请注意过滤 mappings in Universal只会排除 application.dev.conf来自 conf文件夹 而不是来自 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")) }

关于scala - 如何排除conf文件夹下的文件进行分发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24375624/

相关文章:

scala - 我可以使用类的类型注释来决定类方法的结果类型吗?

scala - 在 Spark 中处理 (OSM) PBF 文件

scala - 双冒号(或冒号-冒号)::在 Scala 中是什么意思?

java - 在 Java 中从模板访问 Flash

java - playframework 2.3.4 启动时出现 java 8u25 错误

scala - 谓词成立时重复调用函数

scala - 函数参数: upper bound vs parent class as argument?

scala - SBT 目录结构。 "project"是什么?

gradle 2.6 Play 插件 : How to add play local dependency

playframework - 如何在 Play Framework 2 中测试数据库演变