美文网首页
Mac配置多个gradle版本

Mac配置多个gradle版本

作者: 丹丹无敌 | 来源:发表于2022-07-19 15:06 被阅读0次
    
    export PATH=$PATH:/Users/***/software/gradle/gradle-7.5/bin
    export GRADLE_541_HOME=/Users/***/software/gradle/gradle-5.4.1/bin
    export GRADLE_564_HOME=/Users/***/software/gradle/gradle-5.6.4/bin
    export GRADLE_742_HOME=/Users/***/software/gradle/gradle-7.4.2/bin
    
    alias gradle541='export PATH=$GRADLE_541_HOME:$PATH'
    alias gradle564='export PATH=$GRADLE_564_HOME:$PATH'
    alias gradle742='export PATH=$GRADLE_742_HOME:$PATH'
    
    

    默认使用的是gradle 7.5版本,可以通过gradle541或gradle564来进行切换gradle版本。

    Mac也可以通过brew命令来进行安装

    brew install gradle
    

    通过指定固定文件,来安装指定的gradle版本

     brew install /Users/***/software/gradle/gradle.rb
    

    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-5.4.1-all.zip"
      sha256 "14cd15fc8cc8705bd69dcfa3c8fefb27eb7027f5de4b47a8b279218f76895a91"
      license "Apache-2.0"
    
      livecheck do
        url "https://gradle.org/install/"
        regex(/href=.*?gradle[._-]v?(\d+(?:\.\d+)+)-all\.(?:zip|t)/i)
      end
    
      # bottle do
      #   sha256 cellar: :any_skip_relocation, all: "36f1f1e0d0f96a0e55c67b6938cf1ae170b59a280e2e9839533538e5b575d287"
      # end
    
      depends_on "openjdk"
    
      def install
        rm_f Dir["bin/*.bat"]
        libexec.install %w[bin docs lib src]
        env = Language::Java.overridable_java_home_env
        (bin/"gradle").write_env_script libexec/"bin/gradle", env
      end
    
      test do
        assert_match version.to_s, shell_output("#{bin}/gradle --version")
    
        (testpath/"settings.gradle").write ""
        (testpath/"build.gradle").write <<~EOS
          println "gradle works!"
        EOS
        gradle_output = shell_output("#{bin}/gradle build --no-daemon")
        assert_includes gradle_output, "gradle works!"
      end
    end
    

    需要修改上面文件中url和sha256值,url修改为自己指定版本对应值,sha256可以通过如下命令获取:

     openssl dgst -sha256 gradle-5.6.4-all.zip
    

    可以通过

    brew info gradle
    

    获取本地已安装的gradle版本

    相关文章

      网友评论

          本文标题:Mac配置多个gradle版本

          本文链接:https://www.haomeiwen.com/subject/edoeprtx.html