Search code examples
playframework-2.2

Additional source folder in playframework 2.2 and form binding


I need a second source folder beside app in a playframework 2.2 application. For this, I added to the projects build.sbt:

unmanagedSourceDirectories in Compile += baseDirectory.value / "common_app"

Problem: Form binding is not working anymore with java model classes in common_app/models. Indeed there is difference in the compiled class files - if the form model source file is in common_app/models, the class file is about half of the size.

How can I add the second source folder and have form binding working?


Solution

  • The app source folder is defined in

    /framework/src/sbt-plugin/src/main/scala/PlaySettings.scala
    

    Just append the source lines with "app" to the end of your projects build.sbt and change them to your new source folder (the empty lines are important, and the comma at the end needs to be removed):

    unmanagedSourceDirectories in Compile += baseDirectory.value / "common_app"
    
    sourceDirectory in Compile <<= baseDirectory / "common_app"
    
    //scalaSource in Compile <<= baseDirectory / "common_app"
    
    javaSource in Compile <<= baseDirectory / "common_app"
    
    watchSources <++= baseDirectory map { path => ((path / "common_app") ** "*" --- (path / "common_app/assets") ** "*").get }