brew安装gradle命令:

brew install gradle

这个命令执行的是这个文件:

https://github.com/Homebrew/homebrew-core/blob/master/Formula/gradle.rb

所以下载的是这里的版本,这里的版本一般是最新的


有时候,我们可能想要一些低版本,这个时候可以把上面的那个文件下载到本地:

class Gradle < Formula
  desc "Open-source build automation tool based on the Groovy and Kotlin DSL"
  homepage "https://www.gradle.org/"
  url "https://services.gradle.org/distributions/gradle-6.2.2-all.zip"
  sha256 "838fa0e3373a9c8d953eff972449edc6be5fa12b26509ac3387727de85138cc0"

  bottle :unneeded

  depends_on "openjdk"

  def install
    rm_f Dir["bin/*.bat"]
    libexec.install %w[bin docs lib src]
    (bin/"gradle").write_env_script libexec/"bin/gradle",
      :JAVA_HOME => "${JAVA_HOME:-#{Formula["openjdk"].opt_prefix}}"
  end

  test do
    assert_match version.to_s, shell_output("#{bin}/gradle --version")
  end
end

修改第四行和第五行为自己想要的版本,比如:gradle-4.4.1-all.zip

同时需要sha256一致,这个可以去如下地址看:https://services.gradle.org/distributions   找到对应版本的sha256

改完后,执行本地的gradle.rb:

brew install /export/gradle.rb

如果提示:

To install 4.4.1, first run `brew unlink gradle`.

按照提示执行:brew unlink gradle,去掉原来版本的引用

再次执行:

brew install /export/gradle.rb

 如果提示:

Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
No changes to formulae.

Warning: gradle 6.2.2 is available and more recent than version 4.4.1.
==> Downloading https://services.gradle.org/distributions/gradle-4.4.1-all.zip
==> Downloading from https://downloads.gradle-dn.com/distributions/gradle-4.4.1-
######################################################################## 100.0%
Error: An exception occurred within a child process:
  ChecksumMismatchError: SHA256 mismatch
Expected: 4e318d74d06aa7b998091345c397a3c7c4b291b59da31e6f9c772a596711acac
  Actual: dd9b24950dc4fca7d1ca5f1ccd57ca8c5b9eb407e3e6e0f48174fde4bb19ed06
 Archive: /Users/mayong/Library/Caches/Homebrew/downloads/abe9575f62833dd2cec95f22ff58013ed15dea648bc7fb04b884cf0a33660238--gradle-4.4.1-all.zip
To retry an incomplete download, remove the file above.

说明sha256不对,按照提示的真实的,再改一次,再次执行,就会成功了。

查看gradle版本,执行:

gradle -v

可以看到已经是4.4.1了。

查看当前安装的gradle信息,执行:

brew info gradle

可以看到有两个版本:

gradle: stable 6.2.2
Open-source build automation tool based on the Groovy and Kotlin DSL
https://www.gradle.org/
/usr/local/Cellar/gradle/4.4.1 (9,325 files, 151.5MB) *
  Built from source on 2020-03-22 at 19:55:52
/usr/local/Cellar/gradle/6.2 (11,452 files, 239.9MB)
  Built from source on 2020-02-24 at 12:02:53
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gradle.rb
==> Dependencies
Required: openjdk ✔

切换版本,可以执行:

brew switch gradle 4.4.1

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐