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 ...
随机推荐
- hdu 1011 树形背包
http://blog.csdn.net/libin56842/article/details/9876503 这道题和poj 1155的区别是: poj1155是边的价值,所以从边的关系入手 hdu ...
- POJ1651 Multiplication Puzzle(相邻乘积之和最小,区间DP)
http://blog.csdn.net/libin56842/article/details/9747021 http://www.cnblogs.com/devil-91/archive/2012 ...
- unity3d之相机跟随人物
一.第三人称视角 _1 先设置好相机与玩家之间的角度 给相机添加代码 using UnityEngine; using System.Collections; namespace CompletePr ...
- pom文件解析
Maven的依赖是使用Maven坐标来定位的,而Maven坐标主要由GAV(groupId, artifactId, version)构成.因此,使用任何一个依赖之间,你都需要知道它的Maven坐标. ...
- browserslist 目标浏览器配置表
为什么需要: 根据提供的目标浏览器的环境来,智能添加css前缀,js的polyfill垫片,来兼容旧版本浏览器,而不是一股脑的添加.避免不必要的兼容代码,以提高代码的编译质量. 共享使用browser ...
- Python-并发编程(进程)
接下来我们用几天的时间说一说python中并发编程的知识 一.背景知识 顾名思义,进程即正在执行的一个过程.进程是对正在运行程序的一个抽象. 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作 ...
- C#——DataGridView选中行,在TextBox中显示选中行的内容
C#--DataGridView选中行,在TextBox中显示选中行的内容,在DataGridView的SelectionChanged实践中设置如下代码 private void dataGridV ...
- Android 保存和恢复activity的状态数据
一般来说, 调用onPause()和onStop()方法后的activity实例仍然存在于内存中, activity的所有信息和状态数据不会消失, 当activity重新回到前台之后, 所有的改变都会 ...
- 用虚拟信用卡注册Google Play开发者账号
本文首发于http://www.abcdsxg.cn/free/net/562 虚拟信用卡 首先介绍一下虚拟信用卡(Virtual Credit Card),顾名思义,虚拟就是没有实体卡,一般都是在提 ...
- 微信小程序——组件(一)
接着之前讲解的基础内容,应该对小程序有了一点了解.想深入了解的话,需要自己实际操作一遍比较好.首先了解官方给的组件,API等这样等顺序来比较好一些.下面贴两张demo图,demo的项目结构是设置的两个 ...