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 ...
随机推荐
- spring 代理
java动态代理实现 1. Java自带的动态代理,反射生成字节码 2. Cglib调用asm生成子类 spring 中代理实现 1. 如果类实现了接口,使用java动态代理 2. 没有实现接口,使用 ...
- docker 数据卷挂载总结
原文
- java利用直方图实现图片对比
需求 实现两张图对比,找出其中不同的部分. 分析 首先将大图切片,分成许多小图片.然后进行逐个对比,并设定相似度阈值,判断是否是相同.最后整理,根据生成数组标记不同部分.如果切片足够小,便越能精确找出 ...
- cocos-creator 脚本逻辑-2
1.预制体 1)节点操作 Cc.find(‘node-1’) 获取节点 全局事件 作用于 canvas this.node.destroy() 删除节点(从内存中删除) 添加删除获取节点或组件 let ...
- 数据结构与算法C语言所有头文件汇总 —— 持续更新
header.h // 顺序表的结构定义 #define Maxsize 100 //const int Maxsize = 100; // 预先定义一个足够大的常数 typedef struct { ...
- CentOS 7 禁用IPV6以提高网速
方法 1 编辑文件/etc/sysctl.conf,$vi /etc/sysctl.conf添加下面的行: net.ipv6.conf.all.disable_ipv6 = net.ipv6.conf ...
- sourcemaps and persistent modification in chrome
在现代web开发中,往往我们会借助类似sass,less之类的预处理器来加快开发进度,但是随着项目的增大,你可能无法清楚明确地知道一个css rule到底是从哪个less/scss文件中编译出来的,这 ...
- 故障排除:无法启动、访问或连接到 Azure 虚拟机上运行的应用程序
有多种原因可导致无法启用或连接到在 Azure 虚拟机 (VM) 上运行的应用程序.原因包括应用程序未在预期端口上运行或侦听.侦听端口受到阻止,或网络规则未将流量正确传递到应用程序.本文说明有条理地找 ...
- C++ inheritance examples
1.C++继承经典例子 #include <iostream> using namespace std; class Base { private: int b_number; publi ...
- MySQL案例01:Last_SQL_Errno: 1755 Cannot execute the current event group in the parallel mode
周五同事监控报警,有个MySQL从库复制状态异常,让我帮忙排查下,经过排查发现是MySQL5.6并行复制的一个Bug所致,具体处理过程如下: 一.错误信息 登录mysql从库服务器,检查复制状态 my ...