Hello when working from a Mac m1, Gradle wrapper task reports incorrect architecture compared to gradle :
Here is the result of ./gradlew clean
:
operating system 'Mac OS X'
architecture 'x86-64'
osx
x86_64
x86_64
Here is the result of gradle clean
:
operating system 'Mac OS X'
architecture 'arm-v8'
osx
aarch_64
aarch64
Does someone have an explanation for that.
Additional information : output of gradle --version
------------------------------------------------------------
Gradle 7.4.2
------------------------------------------------------------
Build time: 2022-03-31 15:25:29 UTC
Revision: 540473b8118064efcc264694cbcaa4b677f61041
Kotlin: 1.5.31
Groovy: 3.0.9
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 18.0.1 (Homebrew 18.0.1+0)
OS: Mac OS X 12.2.1 aarch64
here is the content of my build.gradle to display architecture :
println org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.currentOperatingSystem;
println org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.currentArchitecture;
println osdetector.os
println osdetector.arch
println System.getProperty("os.arch")
I generated the Gradle wrapper from my Mac m1 using gradle wrapper
.
Thanks to @Jesper's comment here is a solution to that issue.
List the JVMs on your system and verify that you have at lease one (arm64) JVM.
ā ~ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
18.0.1.1 (arm64) "Oracle Corporation" - "OpenJDK 18.0.1.1" /Users/you/Library/Java/JavaVirtualMachines/openjdk-18.0.1.1/Contents/Home
18.0.1.1 (x86_64) "Oracle Corporation" - "OpenJDK 18.0.1.1" /Users/you/Library/Java/JavaVirtualMachines/openjdk-18.0.1.1-1/Contents/Home
18.0.1 (arm64) "Homebrew" - "OpenJDK 18.0.1" /opt/homebrew/Cellar/openjdk/18.0.1/libexec/openjdk.jdk/Contents/Home
/Users/you/Library/Java/JavaVirtualMachines/openjdk-18.0.1.1/Contents/Home
Setup your JAVA_HOME environment variable to an arm64 JVM :
export JAVA_HOME=`/usr/libexec/java_home -a arm64`
This is caused by multiple JVMs installed on the system. Some JVMs are compiled for arm64 and run natively, and some other are compiled for x86_64 and run in a "translator" (rosetta).
Did not follow the "Caveat" of openJDK :
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
So the homebrew installed gradle was using the homebrew installed JVM. But gradlew scripts were using the default system JVM (the Oracle x86_64 JVM).