How can I specify a compact JRE (as of Java 8) with my gradle builds?


(willbdaniels) #1

While trying to build some projects under Java 8, I noticed that one very attractive feature of the JDK, being able to choose if I want to use one of the compact JRE’s to build against or not, is missing from any gradle documentation I can find.

According to the new JDK documentation, you should be able to pass a javac option -profile but I’m not sure how to manifest this behaviour in gradle.

Any help would be greatly appreciated!

-Will


(Marcin Erdmann) #2

Given that you want to pass that option for your main source set compilation then your compileJava task configuration should contain:

compileJava {
    options.compilerArgs = ["-profile", "compact1"]
}

See here for documentation on how to configure java compiler on a JavaCompile task.


(willbdaniels) #3

Thank you! I tried doing:

compileJava {
     options.compilerArgs = '-profile compact1';
 }

but that threw an error. Your way worked fine.

Much appreciated!


(Marcin Erdmann) #4

Did the solution I suggested work for you?


(willbdaniels) #5

It did indeed, thank you!