JRuby - passing along JAVA_HOME for the JDK

I have an interesting dilemma. I have a nix-shell that includes: jruby & openjdk8_headless.

JRuby sets the JAVA_HOME parameter to the JRE using wrapProgram.

Excerpt from pkgs/development/interpreters/jruby/default.nix

  installPhase = ''
     mkdir -pv $out/docs
     mv * $out
     rm $out/bin/*.{bat,dll,exe,sh}
     mv $out/COPYING $out/LICENSE* $out/docs

     for i in $out/bin/jruby{,.bash}; do
       wrapProgram $i \
         --set JAVA_HOME ${jre}

This means that if I dump out JAVA_HOME in my Ruby program I get


However, I want to have my Ruby script invoke Gradle (gradlew); which requires the JDK.
This works through the shell directly because openjdk8_headless sets JAVA_HOME to be the JDK.

env | grep JAVA

This ultimately gets squashed by the JRuby wrapProgram.

I understand that likely, I can avoid this dilemma if I’m using Gradle managed through my nix-shell; however that’s larger undertaking.

Is there a workaround solution here? Using the gradlew (Gradle wrapper script) is ideal in my setup for now.