Gradle包装器报告X86-64体系结构,而不是Mac M1上的ARM-V8体系结构

发布于 2025-01-28 19:28:49 字数 1228 浏览 4 评论 0原文

您好,从Mac M1工作时,Gradle包装器任务报告与Gradle相比不正确:

这是./ Gradlew Clean Clean的结果:

operating system 'Mac OS X'
architecture 'x86-64'
osx
x86_64
x86_64

这是Gradle Clean Clean的结果:

operating system 'Mac OS X'
architecture 'arm-v8'
osx
aarch_64
aarch64

有人对此有解释吗?

其他信息: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

是我的构建内容。显示架构的Gradle:

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")

我使用gradle包装器从我的Mac M1生成了Gradle包装器。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

演多会厌 2025-02-04 19:28:49

多亏了 @jesper的评论,这里是解决该问题的解决方案。

tl; dr

列出了系统上的JVM,并验证您在租赁一(ARM64)JVM时是否拥有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

设置java_home环境变量JVM

export JAVA_HOME=`/usr/libexec/java_home -a arm64`

在我的情况下发生了什么:

这是由系统上安装的多个JVM引起的。有些JVM用于ARM64并本地运行,另一些则用于X86_64,并在A “翻译器”(Rosetta)

  • Intellij Idea安装的Oracle X86_64 JDK。
  • 由Homebrew安装的OpenJDK ARM64作为Gradle的依赖。

没有遵循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

因此,安装的Gradle安装了Hommbrew已安装了JVM。但是gradlew脚本正在使用默认系统JVM(Oracle X86_64 JVM)。

Thanks to @Jesper's comment here is a solution to that issue.

TL;DR

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`

What happened in my case :

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).

  • Oracle x86_64 JDK installed by intelliJ IDEA.
  • OpenJDK arm64 installed by Homebrew as a dependency of gradle.

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文