13
votes

How do I config build.sbt to exclude src/main/java directory? I would like to put my Java sources there but I don't want to compile them. Also, can I exclude a file or group of files specify with RE. Can these be easily configured in build.sbt?

2
I'm curious, why don't you want the Java files to be compiled?Jim Hurne
I wrote the application in Java and I rewrote the application in Scala. I still want the Java sources to be there as reference but not compile to save compilation time and dependency. No biggie, I can live with Java sources compiled. Also, I want to learn to tweak SBT as part of this exercisethlim
If you're using a source code system like Subversion or git, you can delete with confidence. If you ever have to look at the Java code, it's only a few commands away from restoration (or a few clicks if you have a web interface setup on top of the scm).Jim Hurne

2 Answers

10
votes

javaSource and scalaSource are inputs to unmanagedSourceDirectories. You can then set unmanagedSourceDirectories to be scalaSource only:

unmanagedSourceDirectories in Compile <<=
   scalaSource in Compile apply ( (s: File) => s :: Nil)

or a bit shorter:

unmanagedSourceDirectories in Compile <<= (scalaSource in Compile)( _ :: Nil)

See Classpaths, sources, and resources for details. Also, the inspect command is useful for determining how settings are built up from other settings.

3
votes

Well, there might be a better way but I'd add this to my build.sbt:

javaSource in Compile := file("some/path/that/doesnt/exist")