Setting javac sourcepath (not srcDirs)


(Greg Ward) #1

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?


(Peter Niederwieser) #2

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

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

(Greg Ward) #3

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!


#4

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


(Peter Niederwieser) #5

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.