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 ...
随机推荐
- Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.
Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Xcode7 beta 网络请求报错:The ...
- dev 激活没有权限问题
用管理员身份打开 Microsoft Visual Studio 2010-->Visual Studio Tools-->Visual Studio 命令提示(2010) 然后输入一下命 ...
- 慎把“DataContext”静态化 或则单例
之前在项目里由于把DataContext静态化,最后在测试阶段发现了很多奇怪的问题,后来经过同事的指点 然后上网搜了一翻终于发现 MSDN上说: "请不要试图重用 DataContext ...
- 2.2孙鑫C++
1.继承 动物有 吃 睡 呼吸的方法 当然 鱼也有 不用重复再定义 1)public 那里都可以访问 #include <iostream.h> class Animal //类 基 ...
- 谈谈 Repository、IUnitOfWork 和 IDbContext 的实践
谈谈 Repository.IUnitOfWork 和 IDbContext 的实践 上一篇:<DDD 领域驱动设计-谈谈 Repository.IUnitOfWork 和 IDbContext ...
- EF之外键Include() left join
项目中用EF实现外键查询出的数据, 查询数量正确, 但实现返回数据集数量不对 //DbContext.cs HasRequired(s => s.ClassRoom) .WithMany() . ...
- Entity Framework技术导游系列开篇与热身
在微软平台写程序有年头了,随着微软数据存取技术的持续演化,我在程序中先后使用过ODBC.DAO.ADO.ADO.NET.LINQ to SQL. Entity Framework这些技术. 近几年来, ...
- Using sql azure for Elmah
The MSDN docs contain the list of T-SQL that is either partially supported or not supported. For ex ...
- java加载机制整理
本文是根据李刚的<疯狂讲义>作的笔记,程序有的地方做了修改,特别是路径,一直在混淆,浪费了好多时间!!希望懂的同学能够指导本人,感激尽............ 1.jvm 和 类的关系 当 ...
- Matlab验证公式取值范围
一.问题来源 t = 2xy/(x+y);融合相似度和信任度,我需要验证值域是不是[0,1]: 二.求解 clear all; clc; %linspace(0:1,0.1)这样是错的,第三个参数是段 ...