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. One of the ways to alter the build configuration is with initialization or init scripts. These are like other Gradle scripts but are executed before the build. We can use different ways to add the init script to a build. For example we can use the command-line option -I or --init-script, place the script in the init.d directory of our GRADLE_HOME directory or USER_HOME/.gradle directory or place a file init.gradle in our USER_HOME/.gradle directory.
We can also use the apply(from:) method to include such a script in our build file. We can reference a file location, but also a URL. Imagine we place an init script on our company intranet to be shared by all developers, then we can include the script with the apply(from:) method. In the following build file we use this syntax to include the script:
0.apply plugin: 'java'1.apply from: 'http://intranet/source/quality.gradle'2. 3.version = '2.1.1'4.group = 'com.mrhaki.gradle.sampleThe following script is an init script where we add the Checkstyle plugin to projects with the Java plugin and the Codenarc plugin to projects with the Groovy plugin. Because the Groovy plugin extends the Java plugin the Checkstyle plugin is added to the Groovy project as well.
Notice we also add the downloadCheckstyleConfig task. With this task we download from the intranet the Checkstyle configuration that needs to be used by the Checkstyle tasks.
00.// File: quality.gradle01.allprojects {02.afterEvaluate { project ->03.def groovyProject = project.plugins.hasPlugin('groovy')04.def javaProject = project.plugins.hasPlugin('java')05. 06.if (javaProject) {07.// Add Checkstyle plugin.08.project.apply plugin: 'checkstyle'09. 10.// Task to download common Checkstyle configuration11.// from company intranet.12.task downloadCheckstyleConfig(type: DownloadFileTask) {13.description = 'Download company Checkstyle configuration'14. 15.url = 'http://intranet/source/company-style.xml'16.destinationFile = checkstyle.configFile17.}18. 19.// For each Checkstyle task we make sure20.// the company Checkstyle configuration is 21.// first downloaded.22.tasks.withType(Checkstyle) { 23.it.dependsOn 'downloadCheckstyleConfig'24.}25.}26. 27.if (groovyProject) {28.// Add Codenarc plugin.29.project.apply plugin: 'codenarc'30.}31.}32.}33. 34.class DownloadFileTask extends DefaultTask {35.@Input36.String url37. 38.@OutputFile39.File destinationFile40. 41.@TaskAction42.def downloadFile() {43.destinationFile.bytes = new URL(url).bytes44.}45.}Code written with Gradle 1.2
Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects的更多相关文章
- 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 ...
- 【跟着stackoverflow学Pandas】 - Adding new column to existing DataFrame in Python pandas - Pandas 添加列
最近做一个系列博客,跟着stackoverflow学Pandas. 以 pandas作为关键词,在stackoverflow中进行搜索,随后安照 votes 数目进行排序: https://stack ...
- Gradle Goodness: Run a Build Script With a Different Name
Normally Gradle looks for a build script file with the name build.gradle in the current directory to ...
- Gradle Goodness: Adding Tasks to a Predefined Group
In Gradle we can group related tasks using the group property of a task. We provide the name of our ...
- Gradle Goodness: Add Incremental Build Support to Tasks
Gradle has a very powerful incremental build feature. This means Gradle will not execute a task unle ...
- Gradle Goodness: Add Incremental Build Support to Custom Tasks with Annotations
In a previous post we learned how we can use the inputs and outputs properties to set properties or ...
- Gradle Goodness: Display Available Tasks
To see which tasks are available for our build we can run Gradle with the command-line option -t or ...
- Gradle Goodness: Working with Live Task Collection
Gradle support the definition of so called live collections. These collections are mostly created ba ...
随机推荐
- docker 开机自动启动容器
注意:如果有存在多个容器,都占用了同一端口,那么只会起来一个,要注意,我在调试时候就遇到这个坑了 在使用docker run启动容器时,使用--restart参数来设置: docker run -m ...
- lintcode 题目记录3
Expression Expand Word Break II Partition Equal Subset Sum Expression Expand 字符串展开问题,按照[]前的数字展开字符 ...
- thinkphp怎么把数据库中的列的值存到下拉框中
1. 先去数据库中查值,查询整个数据表,结果为二维数组. $project = M("project"); $cell = $project->where(array('st ...
- Python爬虫教程-31-创建 Scrapy 爬虫框架项目
本篇是介绍在 Anaconda 环境下,创建 Scrapy 爬虫框架项目的步骤,且介绍比较详细 Python爬虫教程-31-创建 Scrapy 爬虫框架项目 首先说一下,本篇是在 Anaconda 环 ...
- 搭建git远程仓库
基于本地协议搭建git远程仓库 1.任意目录下执行git init -bare创建裸仓库,建议目录名称以.git结尾 2.共享此目录,windows下右键裸仓库目录,切换到共享面板设置完成即可获取共享 ...
- 学会利用Ionic官网文档
和任何新技术一样,ionic也提供了详细的官方文档说明.网址如下: http://ionicframework.com/docs/ 学会使用ionic控件 ionic提供了大量优秀的高性能的仿原生控件 ...
- Struts2学习-ssh框架
SSH是 struts+spring+hibernate的一个集成框架,是目前比较流行的一种Web应用程序开源框架. http://www.cnblogs.com/laibin/p/5847111.h ...
- vue记录
vue项目中使用默认图片代替异常图片 第一种方法 <img onerror="javascript:this.src='../../static/custom.png';" ...
- Java中父类强制转换为子类的可能
之前徒弟问了一个问题, 在Java中, 父类对象到底能不能转换成对应的子类对象? 到底能不能, 今天就来说说这个问题, 先看下面一段代码: package cn.com.hanbinit.test; ...
- sql 获取每个分组的前N条记录的写法
SELECT * FROM ( --根据 tb表的name进行分组,根据年龄排序 SELECT * , ROW_NUMBER() OVER ( PARTITION BY name ORDER BY a ...