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 ...
- html+css 布局篇
float 做了float后有一些不好的影响. 1.背景不能显示 由于浮动产生,如果对父级设置了(CSS background背景)CSS背景颜色或CSS背景图片,而父级不能被撑开,所以导致CSS背景 ...
- HTML DOM insertBefore() 方法 问题
写即时通讯时,每次新增的回话插到原有子节点的前面. 但是出现了以下报错的情况 如图: MDC: var insertedElement = parentElement.insertBefore(new ...
- 03_Adaptive注解
[Adaptive注解] package com.alibaba.dubbo.common.extension; import com.alibaba.dubbo.common.URL; import ...
- EF+Oracle
一个小项目,设计到几十张表,但都是简单的增删改查,所以呢,想偷懒用EF. 结果,在.NET4.0下,死活都不行.最后在Oracle官方找到demo,上面清清楚楚的写着必须>NET4.5. 看着E ...
- Hush Framework框架配置(续) 转自《Android和PHP最佳实践》官方站
图书资源下载 Xampp 开发环境下载:http://pan.baidu.com/share/link?shareid=531771&uk=773037279 微博实例完整源码包下载:http ...
- Selenium_Python接口-Alert类
Alert类的路径:from selenium.webdriver.common.alert import Alert Alert类主要是一些对弹出框的操作,如:获取属性.确认.取消等 接口内容: f ...
- 如何判断单链表是否存在环 & 判断两链表是否相交
给定一个单链表,只给出头指针h: 1.如何判断是否存在环? 2.如何知道环的长度? 3.如何找出环的连接点在哪里? 4.带环链表的长度是多少? 解法: 1.对于问题1,使用追赶的方法,设定两个指针sl ...
- Process.start: how to get the output?
1: Synchronous example static void runCommand() { Process process = new Process(); process.StartInfo ...
- 关于TCHAR和string对象的c.str()一些注意事项
1.TCHAR 根据预处理器的设置,如果是_MBCS, 那么TCHAR = char: 如果 如果设置的是UNICODE和_UNICODE,那么TCHAR=wchar_t.就等于根据当前环境会选择不同 ...