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.sample
The 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.gradle
01.
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 configuration
11.
// 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.configFile
17.
}
18.
19.
// For each Checkstyle task we make sure
20.
// 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.
@Input
36.
String url
37.
38.
@OutputFile
39.
File destinationFile
40.
41.
@TaskAction
42.
def
downloadFile() {
43.
destinationFile.bytes =
new
URL(url).bytes
44.
}
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 ...
随机推荐
- SQL COUNT DISTINCT
Create table trade ( sell_id int, --卖家 buy_id int, -- 卖家 time date --交易时间 ) sell_id, buy_id, time s ...
- SPOJ2666 QTREE4
我是萌萌的传送门 我是另一个萌萌的传送门 一道树分治……简直恶心死了……我在调代码的时候只想说:我*************************************************…… ...
- 基于svg.js实现对图形的拖拽、选择和编辑操作
本文主要记录如何使用 svg.js 实现对图形的拖拽,选择,图像渲染及各类形状的绘制操作. 1.关于SVG SVG 是可缩放的矢量图形,使用XML格式定义图像,可以生成对应的DOM节点,便于对单个图形 ...
- RoadFlow工作流与JUI(DWZ)前端框架的集成
此文只说明RoadFlow前端与JUI的集成,关于程序和接口请参照WebForm或MVC文档. 修改JUI配置文件dwz.frag.xml,此文件一般位于JUI根目录下. 2.修改文件js/dwz.n ...
- as3.2版本中中jar生成方法
lintOptions { abortOnError false } task makeJar(type: Copy) { //删除存在的 delete 'build/libs/myjar.jar' ...
- jar 解压war包到指定目录
用 jar -xvf .jar 命令默认解压到当前目录,想要解压到指定目录 需要使用unzip .jar -d 目录 如: unzip pay.war -d /home/zookeeper1/tes ...
- Android学习——自定义控件(二)
这篇文章来介绍自定义组合控件,自定义组合控件的应用场景很多,比如当你的UI如下时: 倘若不使用组合控件,则需要在XML文件中声明4个TextView和4个EditText,而使用了组合控件,则只需要四 ...
- 工作总结:mvc分层架构
pojo:plain ordinary java object 简单无规则java对象,我个人觉得它和其他不是一个层面上的东西,VO和PO应该都属于它 po:persistant object 持久对 ...
- Redis的系统级命令
文章建立一个统一的认识就是Redis的版本是3.2.8 1:BGREWRITEAOF(bgrewriteaof) 执行一个 AOF文件 重写操作.重写会创建一个当前 AOF 文件的体积优化版本. 即使 ...
- python .loc vs .iloc区别
1.loc意义:通过行标签索引行数据 例: loc[n]表示索引的是第n行(index 是整数) loc[‘d’]表示索引的是第’d’行(index 是字符) 2. .iloc :通过行号获取行数 ...