Setting javac sourcepath (not srcDirs)

Our source tree is … interesting. In order to compile anything, I need to pass around 80 distinct directories to javac’s -sourcepath option. (In a nutshell, everything depends on everything.) But if I set those as srcDir properties of my Java sourceSet with Gradle, it tries to compile everything. I don’t want that – yet. I just want to pass the 80 directories as sourcepath dirs.

Haven’t seen anything about sourcepath in the manual and Google didn’t help. Any tips?

I don’t see any direct support for source paths, but you can add additional compiler arguments like so:

compileJava.options.compilerArgs += "-sourcepath ..."

Almost! Looks like compilerArgs is a list, not a string. Here’s what worked for me:

sourcepath = […long list of directories…]

compileJava.options.compilerArgs += ["-sourcepath", sourcepath.join(":")]

Thanks!

+1 on this feature. Any chance this is formally supported in the java plugin now?

It isn’t currently supported directly, but I think it would be a good idea. It would also make sense to use a different default than javac (which defaults sourcepath to classpath), but then this would constitute a breaking change. If you are interested in contributing, let us know.