gradle-plugins
gradle-plugins copied to clipboard
JAVA_HOME set incorrectly on macOS
Using this template:
jdk {
String os = isMacOS() ? 'mac' : isWindows() ? 'win' : 'linux' // mac confirmed, the others are guesses
version = '11.0.5+10'
urlTemplate = "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-${version}/OpenJDK11U-jdk_x64_${os}_hotspot_${version.replace('+', '_')}.tar.gz"
}
Results in the following failure:
Downloading
mv: rename /Users/username/Documents/projectname/.gradle/jdk/jdk11.0.5+10 to /Users/username/Documents/projectname/.gradle/jdk/jdk-11.0.5+10/jdk11.0.5+10: No such file or directory
chmod: -R: No such file or directory
Installed JDK from https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.5+10/OpenJDK11U-jdk_x64_mac_hotspot_11.0.5_10.tar.gz into /Users/username/Documents/projectname/.gradle/jdk/jdk-11.0.5+10
ERROR: JAVA_HOME is set to an invalid directory: /Users/username/Documents/projectname/.gradle/jdk/jdk-11.0.5+10
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
Reason is that on macOS, Java distributions include an extra level of directory hierarchy:
% ls -la /Users/username/Documents/projectname/.gradle/jdk/jdk-11.0.5+10/
total 0
drwxrwxr-x@ 3 username staff 96 15 Jan 06:42 .
drwxr-xr-x 4 username staff 128 15 Jan 06:41 ..
drwxr-xr-x 5 username staff 160 20 Oct 02:11 Contents
% ls -la /Users/username/Documents/projectname/.gradle/jdk/jdk-11.0.5+10/Contents/Home
total 8
drwxr-xr-x 11 username staff 352 20 Oct 02:11 .
drwxr-xr-x 5 username staff 160 20 Oct 02:11 ..
drwxr-xr-x 34 username staff 1088 20 Oct 02:23 bin
drwxr-xr-x 7 username staff 224 20 Oct 02:10 conf
drwxr-xr-x 5 username staff 160 20 Oct 02:10 demo
drwxr-xr-x 9 username staff 288 20 Oct 02:10 include
drwxr-xr-x 72 username staff 2304 20 Oct 02:10 jmods
drwxr-xr-x 72 username staff 2304 20 Oct 02:11 legal
drwxr-xr-x 57 username staff 1824 20 Oct 02:23 lib
drwxr-xr-x 5 username staff 160 20 Oct 02:11 man
-rw-r--r-- 1 username staff 1221 20 Oct 02:11 release
I really wished they had cleaned this up by this point in the JDK's life. :( But in any case I guess this is something that becomes the wrapper's job to deal with. Where should I be looking for a place to fix this?
This is rather interesting too: chmod: -R: No such file or directory
It's almost as if the chmod command has the flags and the arguments the wrong way around? I don't think that would change anything important relating to the actual paths to the files though, so maybe I have simply spotted a second bug.
thank you for the hint. The main logic resides in https://github.com/rmee/gradle-plugins/blob/master/jdk-bootstrap/src/main/resources/bootstrap.sh.template. And it is accessed and templated by GenerateBootstrapScript
. Do you see by chance the fix? There already is some logic in place for the Contents
directory. But might be insufficient. If you see the fix right away, would be great. Because I don't have a mac. Can then also do a public new release to jcenter.
Ah, there is already something in there...
So, the structure I see in the releases in 11.0.6 are like this:
% tar ztf OpenJDK11U-jdk_x64_mac_hotspot_11.0.6_10.tar.gz|head
jdk-11.0.6+10/
jdk-11.0.6+10/Contents/
jdk-11.0.6+10/Contents/Home/
jdk-11.0.6+10/Contents/MacOS/
jdk-11.0.6+10/Contents/Info.plist
jdk-11.0.6+10/Contents/MacOS/libjli.dylib
jdk-11.0.6+10/Contents/Home/demo/
jdk-11.0.6+10/Contents/Home/man/
jdk-11.0.6+10/Contents/Home/bin/
jdk-11.0.6+10/Contents/Home/include/
But the script is assuming that it won't have the hyphen:
# deal with different naming conventions on OSX
if [ -d "${JDK_CACHE_DIR}/jdk${JDK_VERSION}/Contents" ] ; then
mv "${JDK_CACHE_DIR}/jdk${JDK_VERSION}/Contents/Home" "${JDK_CACHE_DIR}/jdk-${JDK_VERSION}"
rm -R "${JDK_CACHE_DIR}/jdk${JDK_VERSION}"
fi
My local workaround is to rename away the hyphen first:
if [ -d "${JDK_CACHE_DIR}/jdk-${JDK_VERSION}/Contents" ] ; then
mv "${JDK_CACHE_DIR}/jdk-${JDK_VERSION}" "${JDK_CACHE_DIR}/jdk${JDK_VERSION}"
fi
But I don't know whether that's the cleanest way to go about it.
Encountered the same issue. It is specifically an issue with JDK 11 for Mac. Just came to the conclusion that the proposed fix is OK. So far the fork of trejkaz has apparently not been merged?
I see that the PR for this has been merged, would it be possible to cut a new release that includes the fix?