I know the normal pattern is to configure the JDK in Jenkins, choose the JDK in the Jenkins job, have Gradle use that JDK.
However that does not work for me. We use feature/bugfix branches in git and have one Jenkins build that builds all the different branches. The problem is that some branches needs to be build using JDK 1.7 and other using JDK 1.8.
So the idea is to have gradlew download the correct JDK (just like it downloads the correct Gradle version.). That way all branches can be build by the same Jenkins job but with different JDKs.
An added benefit is I can upgrade the JDK on a feature branch, get it compiled and tested before merging into the release branch. That way upgrading JDK is a regular feature and does not require changes in Jenkins.
Is that possible today? Do you have the same problem? How do you fix it?