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 ...
随机推荐
- Discuz x3 UCenter实现同步登陆原理
1.Discuz x3 的登录页面URL是:/member.php?mod=logging&action=login 2.这个登录页面,登录提交的地址是: <form method=&q ...
- Spring课程 Spring入门篇 5-7 advisors
1 简析 1.1 advisor简析(这个不太明白,后续再看吧) 2 代码演练 2.1 环绕通知的综合应用(代码和视频对不上,慕课网讲的本身有问题) 1 简析 1.1 advisor简析( ...
- PHP+Xdebug实现远程调试
以前以为php调试时服务器端和IDE必须在同一台机子上,无意发现xdebug其实是支持远程调试的. 尝试之后发现可以配置成功,还是可以调试代码的感觉爽啊! php所在Ubuntu服务器 ...
- JS 面向对象之继承---多种组合继承
1. 组合继承:又叫伪经典继承,是指将原型链和借用构造函数技术组合在一块的一种继承方式. 下面来看一个例子: function SuperType(name) { this.name = name; ...
- SpringBoot2.0+Mybatis+PageHelper+Redis实现缓存
1.在maven引入相关的依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactI ...
- CSS media query应用中的层叠特性使用最佳实践
media query是css3规范中引入的,它提供了一种responsive design的基础机制:浏览器在不同size的设备中将以不同样式展现网页,这就给一个网页能够适应不同device一种可能 ...
- QT的组合键
https://www.cnblogs.com/Jace-Lee/p/5859293.html
- 在vs2015中使用附加进程的方式调试IIS中的页面
发布网站至IIS-附加到进程调试 Internet Information Services(IIS,互联网信息服务),是由微软公司提供的基于运行Microsoft Windows的互联网基本服务. ...
- nginx导致的session丢失的解决方法
nginx把同一用户的请求分发到了不同的服务器,如果不做处理,就会导致session丢失. 1.粘性IP: 在nginx配置文件中,增加配置, 对IP进行HASH后,散列到服务器. 这个实现最简单.但 ...
- GO语言(四)线程通信
package main import "fmt" func fibon(c,quit chan int) { x,y := , for { select { case c < ...