mac home brew 安裝不同版本的gradle

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章