James Lowry
James Lowry

Reputation: 43

What SBT build setting can I use with the Play! 2 framework that will include specific resources from the source tree on the class path

I would like to add a setting to the build that will copy specific files from a location within src tree so that they are available on the class path in dev and production mode. I don’t want to put them in the public folder because I don’t want them to be available to download. And I don’t want to put them in the conf folder because I want to keep that clean for configuration files.

For example:

app
  -- views
     -- website
        -- view.scala.html
        -- header-module.widget
        -- footer-module.widget

When the application is compiled I would like the class path to include both the *.widget files under classpath:views/website/ and not the view.scala.html because that is processed separately.

I would like to do this by adding an sbt setting where I can provide a filter, I’ve already tried this and some variations, but have not had it working so far:

val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
  // Add your own project settings here
  unmanagedResources in Compile <++= (sourceDirectory in Compile) map {
    base: File => ( base / "views" ** "*. widget ").get
})

Upvotes: 4

Views: 958

Answers (1)

MartinGrotzke
MartinGrotzke

Reputation: 1301

The following inside .settings() should work:

// Add app folder as resource directory so that widget files are in the classpath
unmanagedResourceDirectories in Compile <+= baseDirectory( _ / "app" ),
// but filter out java and html files that would then also be copied to the classpath
excludeFilter in Compile in unmanagedResources := "*.java" || "*.html"

I have s.th. like this in our Build.scala to have mybatis xml files in the classpath and it's working for us.

Upvotes: 5

Related Questions