Trouble with "generated" folder

sbt
eclipse

(Paul Fullbright) #1

We have a plugin (I believe it’s flyway) that is generating JPA metaclasses into a source folder named “generated”. We have added this folder to managed source directories:

managedSourceDirectories in Compile += baseDirectory.value / "generated"

And we also have the following eclipse settings:

EclipseKeys.projectFlavor := EclipseProjectFlavor.Java           // Java project. Don't expect Scala IDE
EclipseKeys.createSrc := EclipseCreateSrc.ValueSet(EclipseCreateSrc.ManagedClasses, EclipseCreateSrc.ManagedResources)  // Use .class files instead of generated .scala files for views and routes
EclipseKeys.preTasks := Seq(compile in Compile) // Compile the project before generating Eclipse files, so that .class files for views and routes are present

Our problems are:

  • when we run “sbt eclipse” the “generated” folder is never added as a source folder
  • when we run “sbt docker:publishLocal” the classes that are in that folder are never found.

Can you tell me what we’re missing?

(Edited to add)
I should mention, that we do not use scala at all. Only java.


(Rich Dougherty) #2

Does the generated directory contain .java or .class files?

If this is an sbt plugin that’s generating the files, it’s usually that plugin’s responsibility to register the directory, is this not happening?


(Paul Fullbright) #3

It contains .java files. It turns out that we are actually specifying the folder to be used for JPA metamodel generation, which is a standard JPA/Hibernate feature.

In build.sbt:

javacOptions ++= Seq(
  "-source", "1.8", 
  "-target", "1.8", 
  "-Xlint", 
  "-s", "generated")

How would we make sure we are registering the directory with sbt properly?


(Marcos Pereira) #4

Hey @PeeDub,

What you want is unmanagedSourceDirectories, not managed. See sbt docs for more details. Given that, you need to change your configuration to:

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

Best.


(Paul Fullbright) #5

OK, I think that works.

I get errors now recompiling, but I’m guessing I need to tie into the sbt generation api.