【问题标题】:sbt-assembly: How do I exclude the configuration files in src/main/resourcessbt-assembly:如何排除 src/main/resources 中的配置文件
【发布时间】:2016-05-11 18:18:09
【问题描述】:

我正在使用来自https://github.com/sbt/sbt-assembly 的 sbtassembly 来打包我的项目。

我想知道是否有排除资源文件?

【问题讨论】:

    标签: scala sbt sbt-assembly


    【解决方案1】:

    您可以通过自定义mergeStrategy 来指定要排除的文件(和路径): https://github.com/sbt/sbt-assembly#excluding-specific-files

    因此,要丢弃特定文件,您可以执行以下操作:

    // build.sbt
    
    assemblyMergeStrategy in assembly := {
      case PathList("about.html") => MergeStrategy.discard
      case x =>
        val oldStrategy = (assemblyMergeStrategy in assembly).value
        oldStrategy(x)
    }
    

    以下是所有可用策略的文档: https://github.com/sbt/sbt-assembly#merge-strategy

    【讨论】:

      【解决方案2】:

      使用 sbt 0.13.13 的 Dani 方法,配置文件仍然包含在我的 jar 中。不过,这很有效:

      excludeFilter in Compile := "myconfig.conf",
      

      在我的例子中,所有文件都具有相同的名称myconfig.conf,但存在于 src/main/resources/config 下的树结构中。我试过了:

      unmanagedResourceDirectories in Compile += { baseDirectory.value / "src/main/resources/config" },
      

      但它从 jar 中删除了目录,留下了文件。

      记录在这里:http://www.scala-sbt.org/0.13/docs/Howto-Customizing-Paths.html

      【讨论】:

        猜你喜欢
        • 2020-07-24
        • 2013-10-30
        • 2015-03-22
        • 1970-01-01
        • 1970-01-01
        • 2015-02-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多