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 printGradleVersionGradle version is 2.2Your Gradle version is 2.2Base version: Gradle 2.2Build time : 2014-11-10 13:31:44 UTCBuild number: noneCommit id : aab8521f1fd9a3484cac18123a72bcfdeb7006ecNext major : Gradle 3.0Snapshot? : false$ gradle -q compareGradleVersionYour 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.
Gradle Goodness: Using and Working with Gradle Version的更多相关文章
- Gradle Goodness: Copy Files with Filtering
Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filterin ...
- Gradle Goodness: Task Output Annotations Create Directory Automatically
Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of ...
- Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects
Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects Gradle is very flexible. ...
- Configuration on demand is not supported by the current version of the Android Gradle plugin since you are using Gradle version 4.6 or above. Suggestion: disable configuration on demand by setting org
androidStudio打开cocos3.17.2Lua项目时,出现了 Configuration on demand is not supported by the current version ...
- 彻底搞懂Gradle、Gradle Wrapper与Android Plugin for Gradle的区别和联系
首先用一段通俗易懂但是不是非常专业的话描述一下三者的概念.区别和联系. Gradle是个构建系统,能够简化你的编译.打包.测试过程.熟悉Java的同学,可以把Gradle类比成Maven. Gradl ...
- Gradle快速上手——从Maven到Gradle
[本文写作于2018年7月5日] 本文适合于有一定Maven应用基础,想快速上手Gradle的读者. 背景 Maven.Gradle都是著名的依赖管理及自动构建工具.提到依赖管理与自动构建,其重要性在 ...
- Gradle项目构建(1)——Gradle的由来
一.项目自动构建介绍 作为Java的开发者对eclipse都非常熟悉,其实eclipse就是居于ant来构建项目的,我们先来看看为什么需要自动化构建项目. 1.为什么我们要自动化构建项目 可以假设我们 ...
- Gradle学习总结——抓重点学Gradle
前言 网上关于Gradle的教程很多,但很多都是以"面"切入- 通过大量讲解其用法及其API分类来阐述.但Gradle API使用技巧众多,API更是成千上百,臣妾记不住呀.个人深 ...
- 解决gradle /Users/xxxx/Documents/workspace/fontmanager/.gradle/2.2.1/taskArtifacts/cache.properties (No such file or directory)报错办法
git 上down下项目后,发现Android Studio报错: What went wrong: java.io.FileNotFoundException: /Users/raomengyang ...
随机推荐
- df du
df命令详细用法 a:显示全部的档案系统和各分割区的磁盘使用情形 i:显示i -nodes的使用量 k:大小用k来表示 (默认值) t:显示某一个档案系统的所有分割区磁盘使用量 x:显示不是某一个档案 ...
- C#中的委托与事件
1,委托? 通俗来讲,就是一个能存放符合某种格式(签名)的方法的指针 的容器 (可以将方法作为一个参数来传递到另一个方法内执行) 定义委托:delegate string DelegateSayHi ...
- 从零开始学ios开发(三):第一个有交互的app
感谢大家的关注,也给我一份动力,让我继续前进.有了自己的家庭有了孩子,过着上有老下有小的生活,能够挤出点时间学习真的很难,每天弄好孩子睡觉已经是晚上10点左右了,然后再弄自己的事情,一转眼很快就到12 ...
- Asp.net mvc与PHP的Session共享的实现
最近在做的一个ASP.NET MVC的项目,要用到第三方的php系统,为了实现两个系统的互联互通.决定将两者的session打通共享.让asp.net mvc 和php 都能正常访问和修改Sessio ...
- 4.FPGA芯片管脚解释
用户I/O:不用解释了. 配置管脚: MSEL[1:0] 用于选择配置模式,比如AS.PS等. DATA0 FPGA串行数据输入,连接到配置器件的串行数据输出管脚. DCLK FPGA串行时钟输出 ...
- Qt 按键长按的处理
keyPressEvent()部分代码: if (e->key() == Qt::Key_A && e->isAutoRepeat()) { if (!mPressFl ...
- 一、换系统wince ---到 linux ubuntu 桌面
今天终于拿到了OK6410,还是比较满意.预装的为wince系统,现要修改为linux 按照 OK6410-A开发板LINUX3.0.1-2013-01用户手册 进行 1.遇到问题.无法写入SD卡( ...
- linux校准时间
Linux下ntpdate时间同步 Ntp服务器安装配置 ntp(Network Time Protocol)协议 RedHat服务器可以下载rpm安装包,然后执行# rpm -ivh ntp-4.2 ...
- CoolShell Puzzle攻略[更新隐藏剧情]
CoolShell博主陈皓做了一个在线的puzzle很有意思,链接在这里,这里记录一下解题的一些步骤. Puzzle 0 ++++++++[>+>++>+++>++++> ...
- 断点续传 (HTTP) 归纳
由于最近项目中要上传较大的文件,基于公司原有的底层框架的局限性,对于大文件的传输都束手无策,基于文件传输的安全性,考虑用断点续传(HTTP)以及FTP上传两种方式实现下面归纳下HTTP续传和FTP上传 ...