How to exclude files under conf folder for distribution?
Asked Answered
S

3

6

I have a application.dev.conf and application.test.conf under my conf folder in my Play 2.3 application but I do not want it to be packaged as part of my distribution? What is the right excludeFilter for it?

Strategy answered 23/6, 2014 at 22:29 Comment(0)
W
3

You could use mappings to exclude both files.

mappings in Universal := {
  val origMappings = (mappings in Universal).value
  origMappings.filterNot { case (_, file) => file.endsWith("application.dev.conf") || file.endsWith("application.test.conf") }
}
Weasel answered 24/6, 2014 at 6:49 Comment(1)
This only removes them from the dist task, they still seem to be present in the .jar file of the project?!Zero
C
5

Actually lpiepiora's answer will do the trick, however note that filtering on mappings in Universal will only exclude application.dev.conf from the conf folder and NOT from the jar itself.

I don't know about the play framework but in general if you have something like this:

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

Doing:

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

would produce the following package structure:

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

However if you look into the jar, you will see that your dev.conf file is still in there:

$ 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

This is actually not really harmful but if you want to remove them too, here is the answer: How to exclude resources during packaging with SBT but not during testing

mappings in (Compile, packageBin) ~= { _.filter(!_._1.getName.endsWith(".dev.conf")) }
Certify answered 1/10, 2018 at 14:24 Comment(0)
W
3

You could use mappings to exclude both files.

mappings in Universal := {
  val origMappings = (mappings in Universal).value
  origMappings.filterNot { case (_, file) => file.endsWith("application.dev.conf") || file.endsWith("application.test.conf") }
}
Weasel answered 24/6, 2014 at 6:49 Comment(1)
This only removes them from the dist task, they still seem to be present in the .jar file of the project?!Zero
T
1

Does an excludeFilter as follows work for you?

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

(The unmanagedResourceDirectories key refers to conf/ by default.)

Tyronetyrosinase answered 2/11, 2014 at 16:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.