With the Gradle wrapper, we have the ability to fix the version of Gradle a build runs against. Having a way to do the same with the JDK would be quite helpful, but all the current ways to do it are not really great.
You could update the Gradle wrapper properties to include it. But this path is going to be different per-platform and per-developer, so you end up with every developer having to manually edit this file after checking things out. You could hack it into the gradlew script so that it uses some other environment variable which has to contain the full path, but this is a little awkward as well.
With Ruby projects, I have a .ruby-version file which specifies which version to use, and rbenv handles running the right ruby executable. For Java projects, a similar tool, jenv, exists. At some point, this tool even added Windows support, though only for PowerShell. But still, this is just one more executable switcher, much like rbenv, and we’d have to have one per development tool, all run before running the Gradle wrapper, so it’s not perfectly convenient.
But the project has a Gradle build file in it, which is supposed to contain a statement of the build’s dependencies. The JDK is a dependency too, but it’s a bit disappointing that it isn’t possible to treat it like all the other ones.
If only we could specify something like:
jdk = 'net.java.openjdk:jdk:1.8.0_112'
Gradle could then unpack that somewhere and know where it is, and we wouldn’t have to keep track of so many things.