When searching for JAVA_HOME under MacOS X, bin/gradle does not follow the procedure recommended by Apple for MacOS X 10.5 and later, which is to call /usr/libexec/java_home (see http://developer.apple.com/library/mac/#qa/qa1170/_index.html). It uses the procedure recommended for MacOS X 10.4, which does not take into account the system settings made with the Java Preferences tool.
A patch is attached. It has been tested under MacOS X 10.5 and 10.6. It should still work fine with MacOS 10.4, but I do not have that system available for testing.