Sort out situation for managed Java sources
See original GitHub issueThe sbt documentation says:
A source generation task should generate sources in a subdirectory of sourceManaged
This works fine for generating Scala sources, but not generating Java sources. The reason is, the Java compiler needs a concept of a compilation root directory, and the one that sbt gives it for all sources in sourceManaged
is sourceManaged
, not sub directories of sourceManaged
. Since the Java package structure must match the Java directory structure, this means in order for the Java generated source files to compile, their package structure needs to be directly under sourceManaged
, not a sub directory of sourceManaged
.
So this causes confusion, for example, sbt-idea follows the documentation, and treats sub directories of sourceManaged
as source directories, which causes any Java files generated in sourceManaged
to not compile from IntelliJ’s perspective. See https://github.com/mpeltonen/sbt-idea/pull/257. This causes a problem particularly with Play, see https://github.com/playframework/playframework/issues/2941.
One possible solution is https://github.com/sbt/sbt/issues/753, but I think the documentation should simply be updated to say something like:
A source generation task should generate sources in
sourceManaged
, or if it wants to keep the source files it generates separate from other source generation tasks, it should generate sources to a sub directory incrossTarget
and add that directory tomanagedSourceDirectories
.
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (4 by maintainers)
The short-term workaround might be to recommend against using
(sourceManaged in Compile).value
altogether, and each plugin roll out their own directory undertarget
, and append tomanagedSourceDirectories in Compile
.The solution @eed3si9n suggested seems to work well. I finally got around to trying it in https://github.com/sbt/sbt-xjc/commit/4a0c67c7157aa04744860fe8835951c371641a80. I’ve released a new version (0.10) of sbt-xjc with the fix