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 ...
随机推荐
- C#学习笔记14
1.在多个线程的同步数据中,避免使用this.typeof(type).string进行同步锁,使用这3个容易造成死锁. 2.使用Interlocked类:我们一般使用的互斥锁定模式(同步数据)为Lo ...
- promose
function runAsync1(){ var p = new Promise(function(resolve, reject){ //做一些异步操作 setTimeout(function() ...
- Python-常用模块1
今天我们来看一看python中的常用的模块,内容有点多,我会分两天来更新这些知识 一.什么是模块 模块就是我们把装有特定功能的代码就行归类的结果,从代码编写的单位来看我们的程序,从小到大的顺序:一条代 ...
- React - React Developer Tools开发者工具的安装与使用(Chrome调试插件)
原文地址:http://www.cnplugins.com/zhuanti/how-to-use-react-tools.html 虽然我们曾经在React开发者工具的基础介绍里面有概括性的介绍过Re ...
- 使用jQuery操作input的value值
表单控件是我们的重中之重,因为一旦牵扯到数据交互,离不开form表单的使用,比如用户的注册登录功能等 那么通过上节知识点我们了解到,我们在使用jquery方法操作表单控件的方法: $(selector ...
- 第三周 day3 python学习笔记
1.字符串str类型,不支持修改. 2.关于集合的学习: (1)将列表转成集合set:集合(set)是无序的,集合中不会出现重复元素--互不相同 (2)集合的操作:交集,并集.差集.对称差集.父集.子 ...
- pg 关于不插入重复字段的方法
首先在表的某列加入唯一约束 alter table language_pms add CONSTRAINT language_pms_unique unique(xml); insert into l ...
- 用sql语句实现年龄分段统计
SELECT CASE WHEN (age >= 10 AND age <= 20) THEN '10-20' WHEN (age >= 21 AND age <= 30) T ...
- servlet api.jar是干什么的?
支持servlet的jar包.应该叫servlet-api.jar你如果编写过servlet就知道要用到HttpServletRequest和HttpServletResponse等对象,这些对象都是 ...
- 配置tomcat远程debug
Linux系统中在编辑catalina.sh文件,修改JAVA_OPTS的变量值为如下即可. JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS -Xdebug -Xrunjd ...