Sourceset compile options?


(rajesh.eq) #1

Is it possible to provide compile options to sourceset? For example If I want to use Java compilation otpion fork, how to apply it to the sourceset?


(Attila Kelemen) #2

You have to adjust the associated ‘JavaCompile’ task. For example, if you have a “mySourceSet” source set, then you will have a “compileMySourceSetJava” which you can configure. See the DSL doc about ‘JavaCompile’


(rajesh.eq) #3

Hi can you provide an example of how to configure please. When I tried adding a

task compileMySourceSetJava(type: JavaCompile) { options.fork = true options.forkOptions.executable = myjavacExecutable }

Cannot add task ‘:compileMySourceSetJava’ as a task with that name already exists. I cant see an example of how to configure it.


(Attila Kelemen) #4

‘compileMySourceSetJava’ is automatically added by the Java plugin. So you should just do this:

compileMySourceSetJava.options.fork = true
compileMySourceSetJava.options.forkOptions.executable = myjavacExecutable

(rajesh.eq) #5

I am getting the error “Could not find property ‘compileMySourceSetJava’ on root project” when I add the above code in my script. Could you please clarify where the above script should be present in build script…


(rajesh.eq) #6

Thanks Attila. worked for me.