Gradle build: bootstrap class path not set in conjunction with -source 1.7
Building of a Gradle project yields the following warning:
:compileJavawarning: [options] bootstrap class path not set in conjunction with -source 1.7 1 warning
That happens whenever the project is compiled to be compatible with an older Java version compared to the installed JDK (Java 8 in my case).
build.gradle apply plugin: 'java' sourceCompatibility = 1.7 ...
The warning indicates that Gradle has no access to the legacy JDK (1.7). The issue is in fact with the Java compiler. According to the javac docs you are supposed to provide path to the bootstrap classes rt.jar.
You can easily verify the issue is not with Gradle. Let’s pick any of your source files and try to compile them.
Check the installed JDK
$ java -version java version "1.8.0_51" Java(TM) SE Runtime Environment (build 1.8.0_51-b16) Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Compile the source code with default settings
$ javac src/main/java/Library.java
No warnings, all is good. Now specify the -source flag, which is equivalent to the souceCompatibility property in your build file.
$ javac -source 1.7 src/main/java/Library.java warning: [options] bootstrap class path not set in conjunction with -source 1.7 1 warning
See? You get the same warning you were getting when running gradle build. Now add the -target flag, which maps to targetCompatibility in Gradle’s Java plugin.
$ javac -source 1.7 -target 1.7 src/main/java/Library.java warning: [options] bootstrap class path not set in conjunction with -source 1.7
That change had no effect, because … let me quote the javac docs:
You must specify the -bootclasspath option to specify the correct version of the bootstrap classes (the rt.jar library). If not, then the compiler generates a warning:
javac -source 1.7 OldCode.java warning: [options] bootstrap class path not set in conjunction with -source 1.7