SlideShare a Scribd company logo
Gradle Plugin Goodness
@BRWNGRLDEV
@BRWNGRLDEV
apply plugin: 'checkstyle'

apply plugin: 'findbugs'

apply plugin: 'pmd'



task checkstyle(type: Checkstyle) {

description 'Checks if the code is somewhat acceptable'

group 'verification'



configFile file('./qa-check/checkstyle.xml')

source 'src'

include '**/*.java'

exclude '**/gen/**'



classpath = files()

ignoreFailures = false

}



task findbugs(type: FindBugs) {

apply plugin: 'checkstyle'

apply plugin: 'findbugs'

apply plugin: 'pmd'



task checkstyle(type: Checkstyle) {

description 'Checks if the code is somewhat acceptable'

group 'verification'



configFile file('./qa-check/checkstyle.xml')

source 'src'

include '**/*.java'

exclude '**/gen/**'



classpath = files()

ignoreFailures = false

}



task findbugs(type: FindBugs) {

description 'Run findbugs'

group 'verification'



classes = files("$project.buildDir/intermediates/classes")

source 'src'

classpath = files()



effort 'max'

excludeFilter file('./qa-check/findbugs-exclude.xml')



reports {

xml.enabled = true

html.enabled = false

}



ignoreFailures = true

}



task pmd(type: Pmd) {

description 'Run PMD'

group 'verification'



ruleSetFiles = files("./qa-check/pmd-ruleset.xml")

ruleSets = []



source 'src'

include '**/*.java'

exclude '**/gen/**'



reports {

xml.enabled = false

html.enabled = true

}



ignoreFailures = true

}
apply plugin: 'info.adavis.qualitychecks'
OVERVIEW
▸Gradle Task
▸Plugin Skeleton
▸Dependencies
▸Plugin Classes
▸Publishing
@BRWNGRLDEV
GRADLE TASKS
@BRWNGRLDEV
GRADLE BUILD
@BRWNGRLDEV
PROJECT
TASK TASK TASK
BUILD
GRADLE BUILD LIFECYCLE
@BRWNGRLDEV
TASK
TASK TASK
TASK TASK
EXAMPLE TASK
@BRWNGRLDEV
I want to ask you for your name.
1. Say Hello
2. Ask for your name
DEFINING A TASK
@BRWNGRLDEV
task sayHello {
doLast {
println “Hello.”
}
}
DEFINING A TASK
@BRWNGRLDEV
task askYourName {
dependsOn “sayHello”
doLast {
println “What is your name?”
}
}
task sayHello {
doLast {
println “Hello.”
}
}
EXECUTING A TASK
@BRWNGRLDEV
PLUGIN
@BRWNGRLDEV
PROJECT
TASK TASK TASK
BUILD
TASK TASK
TASK
PLUGIN
CREATING PLUGINS
▸build.gradle file
▸buildSrc directory
▸separate project
PLUGIN - BUILD.GRADLE FILE
@BRWNGRLDEV
PLUGIN - BUILD.GRADLE FILE
@BRWNGRLDEV
apply plugin: 'checkstyle'

apply plugin: 'findbugs'

apply plugin: 'pmd'



task checkstyle(type: Checkstyle) {

description 'Checks if the code is somewhat acceptable'

group 'verification'



configFile file('./qa-check/checkstyle.xml')

source 'src'

include '**/*.java'

exclude '**/gen/**'



classpath = files()

ignoreFailures = false

}



task findbugs(type: FindBugs) {

description 'Run findbugs'

group 'verification'



classes = files("$project.buildDir/intermediates/classes")

source 'src'

classpath = files()



effort 'max'

excludeFilter file('./qa-check/findbugs-exclude.xml')



reports {

xml.enabled = true

html.enabled = false

}



ignoreFailures = true

}



task pmd(type: Pmd) {

description 'Run PMD'

group 'verification'



ruleSetFiles = files("./qa-check/pmd-ruleset.xml")

ruleSets = []



source 'src'

include '**/*.java'

exclude '**/gen/**'



reports {

xml.enabled = false

html.enabled = true

}



ignoreFailures = true

}
apply plugin: 'info.adavis.qualitychecks'
PLUGIN SKELETON
@BRWNGRLDEV
PLUGIN SKELETON
@BRWNGRLDEV
PLUGIN SKELETON
@BRWNGRLDEV
PLUGIN SKELETON
How Gradle finds the Plugin Implementation
@BRWNGRLDEV
DEPENDENCIES
@BRWNGRLDEV
DEPENDENCIES
apply plugin: ‘groovy'
dependencies {
compile gradleApi()
compile localGroovy()
}
@BRWNGRLDEV
DEPENDENCIES
dependencies {
…
testCompile 'junit:junit:4.12'

testCompile ('org.spockframework:spock-core:1.0-groovy-2.4') {

exclude module: 'groovy-all'

}
}
@BRWNGRLDEV
THE CODE
@BRWNGRLDEV
PLUGIN.GROOVY
class CustomPlugin implements Plugin<Project> {
}
@BRWNGRLDEV
PLUGIN.GROOVY
class CustomPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
}
}
@BRWNGRLDEV
QUALITYCHECKSPLUGIN.GROOVY
@BRWNGRLDEV
APPLY METHOD
@BRWNGRLDEV
void apply(Project project) {

this.project = project



}
APPLY METHOD
@BRWNGRLDEV
void apply(Project project) {

this.project = project



project.extensions.create('qualityChecks', QualityChecksExtension)



}
APPLY METHOD
@BRWNGRLDEV
void apply(Project project) {

this.project = project



project.extensions.create('qualityChecks', QualityChecksExtension)



createConfigFilesIfNeeded()

createConfigFileTasks()

createQualityChecksTasks()

}
PROJECT EXTENSION
@BRWNGRLDEV
class QualityChecksExtension {



String pmdConfigFile = 'quality-checks/pmd-ruleset.xml'



String checkstyleConfigFile = 'quality-checks/checkstyle.xml'



String findBugsExclusionFile = 'quality-checks/findbugs-exclude.xml'



}
PROJECT EXTENSION
@BRWNGRLDEV
class QualityChecksExtension {



String pmdConfigFile = 'quality-checks/pmd-ruleset.xml'



String checkstyleConfigFile = 'quality-checks/checkstyle.xml'



String findBugsExclusionFile = 'quality-checks/findbugs-exclude.xml'



}
PROJECT EXTENSION
Back in the application’s build.gradle file…
@BRWNGRLDEV
qualityChecks {

pmdConfigFile = ‘checks/pmd.xml’
checkstyleConfigFile = ‘checks/checkstyle.xml’

}
PROJECT EXTENSION
Back in the application’s build.gradle file…
@BRWNGRLDEV
qualityChecks {

pmdConfigFile = ‘checks/pmd.xml’
checkstyleConfigFile = ‘checks/checkstyle.xml’

}
TASKS
@BRWNGRLDEV
CREATING TASKS
Give it a name and a type
@BRWNGRLDEV
CREATING TASKS
@BRWNGRLDEV
Build on existing task
Extend the DefaultTask
BUILD ON EXISTING TASK
@BRWNGRLDEV
BUILD ON EXISTING
@BRWNGRLDEV
EXTEND DEFAULT TASK
@BRWNGRLDEV
CUSTOMTASK.GROOVY
class CustomTask extends DefaultTask {
CustomTask() {
group: ‘verification’
}
}
@BRWNGRLDEV
CUSTOMTASK.GROOVY
class CustomTask extends DefaultTask {
CustomTask() {
group: ‘verification’
}
}
@BRWNGRLDEV
CUSTOMTASK.GROOVY
CustomTask() {
group: ‘verification’
onlyIf {
// skip under certain conditions
}
}
@BRWNGRLDEV
CUSTOMTASK.GROOVY
@TaskAction
def defaultAction() {
description: ‘What my task does’
}
@BRWNGRLDEV
CUSTOMTASK.GROOVY
@BRWNGRLDEV
@TaskAction
def defaultAction() {
description: ‘What my task does’
<do your cool stuff here>
}
GRADLE TASK DOCUMENTATION
@BRWNGRLDEV
SO FAR…
▸Gradle Tasks
▸Plugin Skeleton
▸Dependencies
▸Plugin Classes
@BRWNGRLDEV
PUBLISHING
@BRWNGRLDEV
PUBLISHING
@BRWNGRLDEV
PUBLISHING
buildscript {
…
dependencies {
classpath "com.gradle.publish:plugin-publish-plugin:0.9.4"
}
}
apply plugin: 'com.gradle.plugin-publish'
@BRWNGRLDEV
PUBLISHING
version = "0.1.3"
group = "info.adavis"
@BRWNGRLDEV
PUBLISHING
pluginBundle {
website = 'https://github.com/adavis/quality-checks'
vcsUrl = 'https://github.com/adavis/quality-checks.git'
description = 'Gradle Plugin for…’
tags = ['Checkstyle', 'FindBugs', 'PMD']
}
@BRWNGRLDEV
PUBLISHING
pluginBundle {
…
plugins {
qualityChecksPlugin {
id = 'info.adavis.qualitychecks'
displayName = 'Quality Checks Plugin'
}
}
@BRWNGRLDEV
@BRWNGRLDEV
@BRWNGRLDEV
WE’RE DONE…
WRONG!
@BRWNGRLDEV
WE’RE DONE…
TESTS
@BRWNGRLDEV
TESTING - WITH JUNIT
@Before

void setUp()
{

project = ProjectBuilder.builder().build()

task = project.tasks.create('writeConfigFile', WriteConfigFileTask)

}
@BRWNGRLDEV
TESTING - WITH JUNIT
@Test
void shouldBeAbleToCreateTask()
{
assertTrue(task instanceof WriteConfigFileTask)
}
@BRWNGRLDEV
TESTING - WITH JUNIT
@Test
void pluginShouldBeApplied()
{
project.apply(plugin: QualityChecksPlugin)
assertNotNull(project.tasks.findByName(‘mytask’))
}
@BRWNGRLDEV
SPOCK
@BRWNGRLDEV
TESTING - WITH SPOCK
def createCheckstyleTask() {

given: "we have a project"

def project = ProjectBuilder.builder().build()


}
TESTING - WITH SPOCK
def createCheckstyleTask() {



and: "we apply the extension"

project.extensions.create('qualityChecks', QualityChecksExtension)



and: "we supply an existing checkstyle config file"

project.qualityChecks.checkstyleConfigFile = File.createTempFile('temp', '.xml').path

}
TESTING - WITH SPOCK
def createCheckstyleTask() {



when: "we create a checkstyle task"

def checkstyleTask = project.tasks.create('checkstyle', CheckstyleTask)





}
TESTING - WITH SPOCK
def createCheckstyleTask() {



then: "it should not replace our previous file"

checkstyleTask.configFile.name.startsWith('temp')

}
TESTING - WITH SPOCK
@BRWNGRLDEV
TESTING - REPORT
@BRWNGRLDEV
TESTING - SPOCK-REPORT
dependencies {
…
testCompile( 'com.athaydes:spock-reports:1.2.12' ) {

transitive = false
}
}
@BRWNGRLDEV
TESTING - SPOCK-REPORT
@BRWNGRLDEV
@BRWNGRLDEV
BONUS: README
@BRWNGRLDEV
BONUS: README
@BRWNGRLDEV
BONUS: README
@BRWNGRLDEV
SUMMARY
▸Gradle Build Basics
▸Creating Task
▸Benefits of Plugins
▸Testing techniques
▸Easy to publish
@BRWNGRLDEV
THANKS!
@brwngrldev
+AnnyceDavis
www.adavis.info
@BRWNGRLDEV

More Related Content

What's hot (20)

PDF
Advanced Jasmine - Front-End JavaScript Unit Testing
Lars Thorup
 
PDF
Test driven node.js
Jay Harris
 
PDF
Redux for ReactJS Programmers
David Rodenas
 
PDF
Testing most things in JavaScript - LeedsJS 31/05/2017
Colin Oakley
 
PDF
Understanding JavaScript Testing
jeresig
 
PDF
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
PDF
Angular testing
Raissa Ferreira
 
PDF
Building a Pyramid: Symfony Testing Strategies
CiaranMcNulty
 
PDF
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
PDF
Testing javascript in the frontend
Frederic CABASSUT
 
PPTX
Understanding JavaScript Testing
Kissy Team
 
PPT
Test driven development_for_php
Lean Teams Consultancy
 
KEY
Taking a Test Drive
Graham Lee
 
PDF
Java Script Best Practices
Enrique Juan de Dios
 
ODP
Getting to Grips with SilverStripe Testing
Mark Rickerby
 
PDF
Intro to Cocoa KVC/KVO and Bindings
Sergio Acosta
 
PPTX
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
PDF
Better Code through Lint and Checkstyle
Marc Prengemann
 
PDF
Introduction to Protractor
Jie-Wei Wu
 
PDF
Workshop quality assurance for php projects - ZendCon 2013
Michelangelo van Dam
 
Advanced Jasmine - Front-End JavaScript Unit Testing
Lars Thorup
 
Test driven node.js
Jay Harris
 
Redux for ReactJS Programmers
David Rodenas
 
Testing most things in JavaScript - LeedsJS 31/05/2017
Colin Oakley
 
Understanding JavaScript Testing
jeresig
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
Angular testing
Raissa Ferreira
 
Building a Pyramid: Symfony Testing Strategies
CiaranMcNulty
 
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
Testing javascript in the frontend
Frederic CABASSUT
 
Understanding JavaScript Testing
Kissy Team
 
Test driven development_for_php
Lean Teams Consultancy
 
Taking a Test Drive
Graham Lee
 
Java Script Best Practices
Enrique Juan de Dios
 
Getting to Grips with SilverStripe Testing
Mark Rickerby
 
Intro to Cocoa KVC/KVO and Bindings
Sergio Acosta
 
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
Better Code through Lint and Checkstyle
Marc Prengemann
 
Introduction to Protractor
Jie-Wei Wu
 
Workshop quality assurance for php projects - ZendCon 2013
Michelangelo van Dam
 

Similar to Creating Gradle Plugins - Oredev (20)

PDF
Idiomatic gradle plugin writing
Schalk Cronjé
 
PDF
Idiomatic Gradle Plugin Writing
Schalk Cronjé
 
PDF
Idiomatic Gradle Plugin Writing
Schalk Cronjé
 
PDF
Idiomatic Gradle Plugin Writing
Schalk Cronjé
 
PDF
Idiomatic Gradle Plugin Writing - GradleSummit 2016
Schalk Cronjé
 
PDF
Basic Gradle Plugin Writing
Schalk Cronjé
 
PDF
Improving your Gradle builds
Peter Ledbrook
 
PDF
Gradle plugin, take control of the build
Eyal Lezmy
 
PDF
In the Brain of Hans Dockter: Gradle
Skills Matter
 
PDF
Making the most of your gradle build - Greach 2017
Andres Almiray
 
PDF
Making the most of your gradle build - Gr8Conf 2017
Andres Almiray
 
PDF
Gradle Introduction
Dmitry Buzdin
 
PDF
Gradleintroduction 111010130329-phpapp01
Tino Isnich
 
PDF
Making the Most of Your Gradle Build
Andres Almiray
 
PPTX
GradleFX
Christophe Herreman
 
PDF
Making the Most of Your Gradle Build
Andres Almiray
 
PDF
Enter the gradle
Parameswari Ettiappan
 
PPT
Groovy Maven Builds
Evgeny Goldin
 
PDF
Gradle For Beginners (Serbian Developer Conference 2013 english)
Joachim Baumann
 
PPTX
A brief guide to android gradle
Leonardo YongUk Kim
 
Idiomatic gradle plugin writing
Schalk Cronjé
 
Idiomatic Gradle Plugin Writing
Schalk Cronjé
 
Idiomatic Gradle Plugin Writing
Schalk Cronjé
 
Idiomatic Gradle Plugin Writing
Schalk Cronjé
 
Idiomatic Gradle Plugin Writing - GradleSummit 2016
Schalk Cronjé
 
Basic Gradle Plugin Writing
Schalk Cronjé
 
Improving your Gradle builds
Peter Ledbrook
 
Gradle plugin, take control of the build
Eyal Lezmy
 
In the Brain of Hans Dockter: Gradle
Skills Matter
 
Making the most of your gradle build - Greach 2017
Andres Almiray
 
Making the most of your gradle build - Gr8Conf 2017
Andres Almiray
 
Gradle Introduction
Dmitry Buzdin
 
Gradleintroduction 111010130329-phpapp01
Tino Isnich
 
Making the Most of Your Gradle Build
Andres Almiray
 
Making the Most of Your Gradle Build
Andres Almiray
 
Enter the gradle
Parameswari Ettiappan
 
Groovy Maven Builds
Evgeny Goldin
 
Gradle For Beginners (Serbian Developer Conference 2013 english)
Joachim Baumann
 
A brief guide to android gradle
Leonardo YongUk Kim
 
Ad

More from Annyce Davis (17)

PDF
Getting a Grip on GraphQL
Annyce Davis
 
PDF
RxJava In Baby Steps
Annyce Davis
 
PDF
No internet? No Problem!
Annyce Davis
 
PDF
First Do No Harm - 360|AnDev
Annyce Davis
 
PDF
First Do No Harm - Droidcon Boston
Annyce Davis
 
PDF
Developing Apps for Emerging Markets
Annyce Davis
 
PDF
Develop Maintainable Apps - edUiConf
Annyce Davis
 
PDF
From Grails to Android: A Simple Journey
Annyce Davis
 
PDF
Google I/O 2016 Recap
Annyce Davis
 
PDF
Say It With Video
Annyce Davis
 
PDF
Screen Robots: UI Tests in Espresso
Annyce Davis
 
PDF
Creating Gradle Plugins
Annyce Davis
 
PDF
Static Code Analysis
Annyce Davis
 
PDF
Develop Maintainable Apps
Annyce Davis
 
PDF
Android Testing, Why So Hard?!
Annyce Davis
 
PDF
Measuring Audience Engagement through Analytics
Annyce Davis
 
PDF
DC Media Innovations Kick-Off Meetup
Annyce Davis
 
Getting a Grip on GraphQL
Annyce Davis
 
RxJava In Baby Steps
Annyce Davis
 
No internet? No Problem!
Annyce Davis
 
First Do No Harm - 360|AnDev
Annyce Davis
 
First Do No Harm - Droidcon Boston
Annyce Davis
 
Developing Apps for Emerging Markets
Annyce Davis
 
Develop Maintainable Apps - edUiConf
Annyce Davis
 
From Grails to Android: A Simple Journey
Annyce Davis
 
Google I/O 2016 Recap
Annyce Davis
 
Say It With Video
Annyce Davis
 
Screen Robots: UI Tests in Espresso
Annyce Davis
 
Creating Gradle Plugins
Annyce Davis
 
Static Code Analysis
Annyce Davis
 
Develop Maintainable Apps
Annyce Davis
 
Android Testing, Why So Hard?!
Annyce Davis
 
Measuring Audience Engagement through Analytics
Annyce Davis
 
DC Media Innovations Kick-Off Meetup
Annyce Davis
 
Ad

Recently uploaded (20)

PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PPTX
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PPTX
UI5con_2025_Accessibility_Ever_Evolving_
gerganakremenska1
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PPTX
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
PDF
Best Web development company in india 2025
Greenusys
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PPTX
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
PPTX
Library_Management_System_PPT111111.pptx
nmtnissancrm
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
UI5con_2025_Accessibility_Ever_Evolving_
gerganakremenska1
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
Best Web development company in india 2025
Greenusys
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
Library_Management_System_PPT111111.pptx
nmtnissancrm
 

Creating Gradle Plugins - Oredev