How can I include generated source files when my Play routes and views are compiled?
My Play 2.3 application uses a plugin that generates source files under a sourceManaged subdir (target/scala-2.11/src_managed/main/subdir). These source files include controllers and models that are referenced in my routes files and views. But when I compile my application, I get errors like this:
[error] myapp/conf/routes:14: object Contacts is not a member of package controllers [error] GET /contacts controllers.Contacts.blank()
and this:
[error] myapp/app/views/contact/form.scala.html:1: not found: type Contact [error] @(contactForm: Form[Contact]) [error] ^
Because controllers/Contacts.java and models/Contact.java reside under sourceManaged.
I've tried manually adding the appropriate managed sources subdir to sourceDirectory in Compile and javaSource in Compile in my build.sbt but it did not improve things.
I have considered making the managed source subdir a subproject and then using aggreate(), but it does not have the necessary build.sbt or project files -- it only has Java sources. And it seemed that making a managed source directory into a subproject from might be inappropriate. Should I reconsider this?
First make sure the plugin has a way to be added to sourceGenerators in Compile by your Play project. You can find how to do this here in the sbt documentation. I also have an example in a plugin I wrote, but note that it uses 0.12.x syntax.
Once you've done that, be sure one of your Play project build files adds the settings. This will be as simple as adding the name you used for the settings in the plugin to the build file, like this example of my plugin shows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With