zoukankan      html  css  js  c++  java
  • Gradle Goodness: Using and Working with Gradle Version

    To get the current Gradle version we can use the gradleVersion property of the Gradle object. This returns a string value we can use for displaying the values. If we want to compare Gradle versions we can use the GradleVersion object. With this class we can get the current version, but we can also compare Gradle versions. This can be useful in our build scripts if we have functionality based on a Gradle version.

    In the following build file we first have a task that uses the gradleVersion of Gradle. Then inside the task we use the static method current of the GradleVersion class. We get an GradleVersion instance and we display different properties from this instance. In the task compareGradleVersion we create a GradleVersion instance with the static version method. We compare multiple GradleVersion objects and have different functionality based on the Gradle version.

    00.task printGradleVersion << {
    01.// Get current Gradle version as object.
    02.final GradleVersion gradleVersion = GradleVersion.current()
    03. 
    04.// Print different properties.
    05.println "Your Gradle version is ${gradleVersion.version}"
    06.println "Base version: ${gradleVersion.baseVersion}"
    07.println "Build time  : ${gradleVersion.buildTime}"
    08.println "Build number: ${gradleVersion.buildNumber}"
    09.println "Commit id   : ${gradleVersion.revision}"
    10.println "Next major  : ${gradleVersion.nextMajor}"
    11.println "Snapshot?   : ${gradleVersion.snapshot}"
    12.}
    13. 
    14.task compareGradleVersion << {
    15.// Current Gradle version.
    16.final GradleVersion gradleVersion = GradleVersion.current()
    17. 
    18.// Gradle version 2.1 as GradleVersion object.
    19.final GradleVersion gradle2_1 = GradleVersion.version('2.1')
    20. 
    21.// Compare versions.
    22.if (gradleVersion > gradle2_1) {
    23.println "Your Gradle version is newer than 2.1"
    24.} else if (gradleVersion == gradle2_1) {
    25.println "Your Gradle version is 2.1"
    26.} else {
    27.println "Your Gradle version is older than 2.1"
    28.}
    29.}

    When we run the tasks we get the following output:

    $ gradle -q printGradleVersion
    Gradle version is 2.2
     
    Your Gradle version is 2.2
    Base version: Gradle 2.2
    Build time  : 2014-11-10 13:31:44 UTC
    Build number: none
    Commit id   : aab8521f1fd9a3484cac18123a72bcfdeb7006ec
    Next major  : Gradle 3.0
    Snapshot?   : false
    $ gradle -q compareGradleVersion
    Your Gradle version is newer than 2.1
    $

    Thanks to John Engelman who showed me this class on a pull request for the Gradle Grails plugin.

    Written with Gradle 2.2.

  • 相关阅读:
    Fiddler抓包使用教程-安装配置
    Fiddler抓包使用教程-扫盲篇
    【Python3 爬虫】14_爬取淘宝上的手机图片
    【Python3 爬虫】13_爬取博客园首页所有文章
    【Python3 爬虫】12_代理IP的使用
    【Python】self的用法扫盲
    【Python3 爬虫】11_报错No module named 'requests'
    【Python3 爬虫】10_Beautiful Soup库的使用
    【DB2】国标行业分类存储,通过SQL查询出层级关系
    【Python3 爬虫】09_正则表达式(re.math()、re.search()、re.sub()、全局匹配函数)
  • 原文地址:https://www.cnblogs.com/GoAhead/p/4187494.html
Copyright © 2011-2022 走看看