Search code examples
playframeworkplayframework-2.4sbt-web

Play 2.4.x - Assets duplication


In a Play 2.4.6 app I'm working on the assets are being duplicated in stage/dist tasks.

Basically it is a app with 3 submodules, with all the assets present in the main public folder. I don't have sbt-web enabled and have no webjars dependencies (but from the jar contents Play may be using them somewhere).

If I use PlayKeys.externalizeResources := false I end up with two jar files in the lib folder:

  • myapp-server.myapp-server-0.9.6-assets.jar
  • myapp-server.myapp-server-0.9.6.jar

The first one contains the assets, as it should. The 2nd should contain my main project class files, but it has also a META-INF/resources/webjars/myapp-server/0.9.6 folder containing every asset from the public folder!

If I use PlayKeys.externalizeResources := true I get the exact same behavior, but the extra META-INF/resources folder is present in myapp-server.myapp-server-0.9.6-externalized-resources.jar instead.

So how can I get rid of that extra assets folder? I have a lot of assets so that extra folder adds a lot to the package size...


Solution

  • After some research, it seems that just excluding the extra folder from the "externalized" jar works:

    mappings in (Compile, packageBin) ~= { (ms: Seq[(File, String)]) =>
        ms filterNot { case (file, dest) =>
            dest.contains("resources/webjars")
        }
    }