Pra*_*nna 6 scala sbt playframework-2.3
我在我的Play 2.3应用程序中有一个application.dev.conf和application.test.conf我的conf文件夹,但我不希望它被打包作为我的发行版的一部分?有什么权利excludeFilter?
小智 5
实际上 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
Run Code Online (Sandbox Code Playgroud)
正在做:
mappings in (Universal, ) ++= {
((resourceDirectory in Compile).value * "*").get.filterNot(f => f.getName.endsWith(".dev.conf")).map { f =>
f -> s"conf/${f.name}"
}
}
Run Code Online (Sandbox Code Playgroud)
将产生以下包结构:
hello/
??? lib
? ??? com.world.hello-1234-SNAPSHOT.jar
??? conf
? ??? application.conf
Run Code Online (Sandbox Code Playgroud)
但是,如果您查看 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
Run Code Online (Sandbox Code Playgroud)
这实际上并不是真正有害,但如果您也想删除它们,答案如下:如何在使用 SBT 打包期间而不是在测试期间排除资源
mappings in (Compile, packageBin) ~= { _.filter(!_._1.getName.endsWith(".dev.conf")) }
Run Code Online (Sandbox Code Playgroud)
您可以使用mappings排除这两个文件。
mappings in Universal := {
val origMappings = (mappings in Universal).value
origMappings.filterNot { case (_, file) => file.endsWith("application.dev.conf") || file.endsWith("application.test.conf") }
}
Run Code Online (Sandbox Code Playgroud)