【问题标题】:How to exclude files under conf folder for distribution?如何排除 conf 文件夹下的文件进行分发?
【发布时间】:2014-08-14 01:34:50
【问题描述】:

我在 Play 2.3 应用程序的 conf 文件夹下有一个 application.dev.confapplication.test.conf,但我不希望它作为我的分发的一部分打包?什么是正确的excludeFilter

【问题讨论】:

    标签: scala sbt playframework-2.3


    【解决方案1】:

    实际上 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")) }
    

    【讨论】:

      【解决方案2】:

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

      mappings in Universal := {
        val origMappings = (mappings in Universal).value
        origMappings.filterNot { case (_, file) => file.endsWith("application.dev.conf") || file.endsWith("application.test.conf") }
      }
      

      【讨论】:

      • 这只是将它们从 dist 任务中删除,它们似乎仍然存在于项目的 .jar 文件中?!
      【解决方案3】:

      下面的excludeFilter 对您有用吗?

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

      unmanagedResourceDirectories 键默认指向conf/。)

      【讨论】:

        猜你喜欢
        • 2014-05-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-12
        • 2017-03-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多