Mastering Grails 3 Plugins - Greach 2016

Alvaro Sanchez-Mariscal
Alvaro Sanchez-MariscalSoftware Engineer um VMWare
Mastering Grails 3
Plugins
Álvaro Sánchez-Mariscal
Álvaro Sánchez-Mariscal
Software Engineer
Grails Development Team
sanchezmariscala@ociweb.com
Mastering Grails 3 Plugins - Greach 2016
OCI is the new home of Grails
More at ociweb.com/grails
The Basics
Creating a Grails 3 plugin
$ grails create-plugin myWebPlugin
| Plugin created at /private/tmp/myWebPlugin
$ grails create-plugin myPlugin -profile plugin
| Plugin created at /private/tmp/myPlugin
Understanding profiles
• A profile defines:
• Project’s build.gradle.
• Commands: create-domain-class,
run-app, etc.
• Features: hibernate, json-views, etc.
• Skeleton: files and folders.
plugin vs. web-plugin
Trim your plugin!
Keep clean
• Start with the plugin profile whenever
possible.
• Remove empty and/or unwanted files/
folders.
• Otherwise, the burtbeckwith bot will
send you a cleanup pull request!
The burtbeckwith bot
The burtbeckwith bot
• Watches messy plugin repos and sends a PR
to clean them up.
• 14 pull requests in the last 3 months!
• Likely hundreds in the last years!
The minimal plugin
• Folder containing:
• build.gradle
• src/main/groovy with plugin descriptor.
• Empty grails-app folder.
The plugin descriptor
• A class inside src/main/groovy. Extends
grails.plugins.Plugin.
• Can override methods to define behaviour
in the plugin lifecycle.
• Syntax has changed a bit from Grails 2.
Plugins features
Plugin configuration
• A plugin can define:
• Configuration values for the host Grails app.
• One of plugin.yml or plugin.groovy.
• Configuration for running the plugin as an
application, to test it.
• application.yml / application.groovy.
Excluding content
• In the plugin descriptor:
• In build.gradle:
// resources that are excluded from plugin packaging

def pluginExcludes = [

'**/com/example/myplugin/tests/**'

]
jar {

exclude 'com/example/myplugin/tests/**/**'

}
Command Line extensions
• Use create-script for code generation
commands.
• Runnable with the Grails CLI.
• Use create-command for interacting with a
loaded Grails application.
• Runnable with the Grails CLI or as a Gradle task.
Scripts
• Base class:
org.grails.cli.profile.commands.script.GroovyScriptCommand
import org.grails.cli.interactive.completers.DomainClassCompleter



description( "Generates a controller that performs REST operations" ) {

usage "grails generate-resource-controller [DOMAIN CLASS]"

argument name:'Domain Class', description:"The name of the domain class", required:true

completer DomainClassCompleter

flag name:'force', description:"Whether to overwrite existing files"

}



if(args) {

generateController(*args)

generateViews(*args)

generateUnitTest(*args)

generateFunctionalTest(*args)

} else {

error "No domain class specified"

}
Commands
import grails.dev.commands.ApplicationCommand

import grails.dev.commands.ExecutionContext



class MyCommand implements ApplicationCommand {



@Override

boolean handle(ExecutionContext ctx) {

def dataSource = applicationContext.getBean(DataSource)

//Run some SQL...



return true

}



}
Enhancing artefacts
import grails.artefact.Enhances

import groovy.transform.CompileStatic



@Enhances(['Controller', 'Service'])

@CompileStatic

trait DateSupport {



Date now() {

return new Date()

}



}
Modularisation
Modularisation
• If your plugin becomes to grow, you might
end up creating a monolith.
• You can modularise your plugins as you
would do with your apps.
Modularisation
Monolithic plugin
Multi-module plugin
Modularisation
• Benefits:
• Optional dependencies.
• Smaller JAR files.
• Build logic reuse.
Modularisation setup
• settings.gradle:
include ‘myPlugin-core', ‘myPlugin-domain' //etc
Modularisation setup
• Root build.gradle:
allprojects {

apply plugin:"idea"

}



subprojects { Project project ->

ext {

grailsVersion = project.grailsVersion

gradleWrapperVersion = project.gradleWrapperVersion

}



repositories {

//Common repos

}



version "1.0.0.M1"

group "org.grails.plugins"



apply plugin: "org.grails.grails-plugin"



dependencies {

//Common deps

}

}
Modularisation setup
• Sub-module build.gradle:
dependencyManagement {

imports {

mavenBom "org.grails:grails-bom:$grailsVersion"

}

applyMavenExclusions false

}



dependencies {

compile project(":myPlugin-core")



compile "com.example:library:1.0.0"

}
Aggregating Docs
task aggregateGroovyDoc(type: Groovydoc) {

group = JavaBasePlugin.DOCUMENTATION_GROUP



dependsOn subprojects.groovydoc

source subprojects.groovydoc.source

destinationDir file("${buildDir}/docs/groovydoc")

classpath = files(subprojects.groovydoc.classpath)

groovyClasspath = files(subprojects.groovydoc.groovyClasspath)

}
Publishing
Artifact publication
• Snapshots:
• Using the artifactory Gradle plugin.
• Published in OJO (oss.jfrog.org).
• Releases:
• Using the grails-plugin-publish Gradle plugin.
• Published in Bintray.
Bintray setup
• For Snapshots:
Build setup
artifactory {

contextUrl = 'http://oss.jfrog.org'

publish {

repository {

repoKey = 'oss-snapshot-local'

username = bintrayUser

password = bintrayKey

}

defaults {

publications('maven')

}

}

}



artifactoryPublish {

dependsOn sourcesJar, javadocJar

}
grailsPublish {

user = bintrayUser

key = bintrayKey

portalUser = pluginPortalUser

portalPassword = pluginPortalPassword



repo = 'plugins'

githubSlug = 'alvarosanchez/my-plugin'

license = 'APACHE 2.0'

title = "My Plugin"

desc = "A very cool Grails plugin"

developers = [

alvarosanchez: "Alvaro Sanchez-Mariscal"

]

}
• For Releases:
Build setup
Build setup
• Define rootProject.name in
settings.gradle.
• Define credentials in
~/.gradle/gradle.properties.
Running it
• Snapshot publishing:
• Release publishing:
$ ./gradlew artifactoryPublish
$ ./gradlew publishPlugin notifyPluginPortal
Plugin portals
• Once your packages are published in your
Bintray repo, go to https://
bintray.com/grails/plugins and click
on “Include my package”.
• Grails 3: http://grails.org/plugins.html
• Grails 2: http://grails.org/plugins
Testing
Testing with a profile
• You can create a profile and use it as a TCK
for your plugin:
• Create test apps from that profile.
• Apps come with a set of tests.
• Use features to test different configurations.
Profile descriptor
description: Creates a test app for Spring Security REST plugin

build:

excludes:

- org.grails.grails-core

dependencies:

compile:

- "org.grails.plugins:spring-security-rest:${pluginVersion}"

- "org.grails:grails-datastore-rest-client:5.0.0.RC3"

testCompile:

- "com.codeborne:phantomjsdriver:1.2.1"

- "org.seleniumhq.selenium:selenium-api:2.47.1"

- "org.seleniumhq.selenium:selenium-firefox-driver:2.47.1"
profile.yml.tmpl
Feature descriptor
description: First configuration of GORM

dependencies:

build:

- "org.grails.plugins:hibernate4:5.0.0.RC2"

compile:

- "org.grails.plugins:hibernate4"

- "org.hibernate:hibernate-ehcache"

- "org.grails.plugins:spring-security-rest-gorm:${pluginVersion}"

runtime:

- "com.h2database:h2"
features/gorm1/feature.yml.tmpl
Build setup
task generateProfileConfig << {

copy {

from 'profile.yml.tmpl'

into '.'

rename { String fileName -> fileName.replaceAll '.tmpl', '' }

expand pluginVersion: project.version

}



file('features').eachDir { feature ->

copy {

from "features/${feature.name}/feature.yml.tmpl"

into "features/${feature.name}/"

rename { String fileName -> fileName.replaceAll '.tmpl', '' }

expand pluginVersion: project.version

}

}

}



compileProfile.dependsOn generateProfileConfig
Skeleton
• Put in the skeleton all your test files and
resources.
• You can use features to have different sets of
tests, resources and configuration.
• Define global configuration values in profile’s
root skeleton folder.
Test them all!
for feature in `ls ../spring-security-rest-testapp-profile/features/`

do

grails create-app -profile 

org.grails.plugins:spring-security-rest-testapp-profile:$pluginVersion 

-features $feature $feature && cd $feature && ./gradlew check && cd ..

done
Use case: the Spring
Security REST plugin
¡Muchas gracias!
Álvaro Sánchez-Mariscal
1 von 46

Recomendados

Efficient HTTP applications on the JVM with Ratpack - Voxxed Days Berlin 2016 von
Efficient HTTP applications on the JVM with Ratpack - Voxxed Days Berlin 2016Efficient HTTP applications on the JVM with Ratpack - Voxxed Days Berlin 2016
Efficient HTTP applications on the JVM with Ratpack - Voxxed Days Berlin 2016Alvaro Sanchez-Mariscal
1K views31 Folien
Mastering Grails 3 Plugins - GR8Conf EU 2016 von
Mastering Grails 3 Plugins - GR8Conf EU 2016Mastering Grails 3 Plugins - GR8Conf EU 2016
Mastering Grails 3 Plugins - GR8Conf EU 2016Alvaro Sanchez-Mariscal
969 views46 Folien
Creating applications with Grails, Angular JS and Spring Security - G3 Summit... von
Creating applications with Grails, Angular JS and Spring Security - G3 Summit...Creating applications with Grails, Angular JS and Spring Security - G3 Summit...
Creating applications with Grails, Angular JS and Spring Security - G3 Summit...Alvaro Sanchez-Mariscal
1.8K views32 Folien
Rest with grails 3 von
Rest with grails 3Rest with grails 3
Rest with grails 3Jenn Strater
4K views46 Folien
Creating applications with Grails, Angular JS and Spring Security - GR8Conf E... von
Creating applications with Grails, Angular JS and Spring Security - GR8Conf E...Creating applications with Grails, Angular JS and Spring Security - GR8Conf E...
Creating applications with Grails, Angular JS and Spring Security - GR8Conf E...Alvaro Sanchez-Mariscal
1.1K views21 Folien
Using React with Grails 3 von
Using React with Grails 3Using React with Grails 3
Using React with Grails 3Zachary Klein
2.1K views66 Folien

Más contenido relacionado

Was ist angesagt?

Creating applications with Grails, Angular JS and Spring Security - GR8Conf U... von
Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...
Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...Alvaro Sanchez-Mariscal
1.8K views29 Folien
Desarrollo de aplicaciones con Grails 3, Angular JS y Spring Security von
Desarrollo de aplicaciones con Grails 3, Angular JS y Spring SecurityDesarrollo de aplicaciones con Grails 3, Angular JS y Spring Security
Desarrollo de aplicaciones con Grails 3, Angular JS y Spring SecurityAlvaro Sanchez-Mariscal
815 views28 Folien
Introduction To Grails von
Introduction To GrailsIntroduction To Grails
Introduction To GrailsChristopher Bartling
2.8K views32 Folien
Capybara with Rspec von
Capybara with RspecCapybara with Rspec
Capybara with RspecOmnia Helmi
9.7K views17 Folien
High Performance Microservices with Ratpack and Spring Boot von
High Performance Microservices with Ratpack and Spring BootHigh Performance Microservices with Ratpack and Spring Boot
High Performance Microservices with Ratpack and Spring BootDaniel Woods
2.4K views51 Folien
A Closer Look At React Native von
A Closer Look At React NativeA Closer Look At React Native
A Closer Look At React NativeIan Wang
730 views23 Folien

Was ist angesagt?(20)

Creating applications with Grails, Angular JS and Spring Security - GR8Conf U... von Alvaro Sanchez-Mariscal
Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...
Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...
Desarrollo de aplicaciones con Grails 3, Angular JS y Spring Security von Alvaro Sanchez-Mariscal
Desarrollo de aplicaciones con Grails 3, Angular JS y Spring SecurityDesarrollo de aplicaciones con Grails 3, Angular JS y Spring Security
Desarrollo de aplicaciones con Grails 3, Angular JS y Spring Security
Capybara with Rspec von Omnia Helmi
Capybara with RspecCapybara with Rspec
Capybara with Rspec
Omnia Helmi9.7K views
High Performance Microservices with Ratpack and Spring Boot von Daniel Woods
High Performance Microservices with Ratpack and Spring BootHigh Performance Microservices with Ratpack and Spring Boot
High Performance Microservices with Ratpack and Spring Boot
Daniel Woods2.4K views
A Closer Look At React Native von Ian Wang
A Closer Look At React NativeA Closer Look At React Native
A Closer Look At React Native
Ian Wang730 views
Django rest framework von Blank Chen
Django rest frameworkDjango rest framework
Django rest framework
Blank Chen1.1K views
Write an API for Almost Anything: The Amazing Power and Flexibility of Django... von Caktus Group
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Write an API for Almost Anything: The Amazing Power and Flexibility of Django...
Caktus Group747 views
Building Web Apps in Ratpack von Daniel Woods
Building Web Apps in RatpackBuilding Web Apps in Ratpack
Building Web Apps in Ratpack
Daniel Woods5.4K views
Dropwizard Spring - the perfect Java REST server stack von Jacek Furmankiewicz
Dropwizard Spring - the perfect Java REST server stackDropwizard Spring - the perfect Java REST server stack
Dropwizard Spring - the perfect Java REST server stack
Jacek Furmankiewicz27.8K views
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope... von chbornet
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
chbornet2.2K views
Building RESTful APIs von Silota Inc.
Building RESTful APIsBuilding RESTful APIs
Building RESTful APIs
Silota Inc.4.6K views
Dropwizard and Groovy von tomaslin
Dropwizard and GroovyDropwizard and Groovy
Dropwizard and Groovy
tomaslin12.4K views
Alexander Mostovenko "'Devide at impera' with GraphQL and SSR" von Fwdays
Alexander Mostovenko "'Devide at impera' with GraphQL and SSR"Alexander Mostovenko "'Devide at impera' with GraphQL and SSR"
Alexander Mostovenko "'Devide at impera' with GraphQL and SSR"
Fwdays206 views
第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」 von Tsuyoshi Yamamoto
第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」
第1回名古屋Grails/Groogy勉強会「Grailsを始めてみよう!」
Tsuyoshi Yamamoto981 views

Destacado

G3 Summit 2016 - Dockerize your Grails! von
G3 Summit 2016 - Dockerize your Grails!G3 Summit 2016 - Dockerize your Grails!
G3 Summit 2016 - Dockerize your Grails!Iván López Martín
5.9K views31 Folien
Greach 2016 dockerize your grails von
Greach 2016   dockerize your grailsGreach 2016   dockerize your grails
Greach 2016 dockerize your grailsIván López Martín
1.8K views31 Folien
Devoxx 2015 - Web Application Development using Grails and Docker von
Devoxx 2015 - Web Application Development using Grails and DockerDevoxx 2015 - Web Application Development using Grails and Docker
Devoxx 2015 - Web Application Development using Grails and DockerTed Vinke
4.4K views41 Folien
groovy & grails - lecture 3 von
groovy & grails - lecture 3groovy & grails - lecture 3
groovy & grails - lecture 3Alexandre Masselot
748 views80 Folien
Connecting Connect with Spring Boot von
Connecting Connect with Spring BootConnecting Connect with Spring Boot
Connecting Connect with Spring BootVincent Kok
1.1K views109 Folien
From Grails to Android: A Simple Journey von
From Grails to Android: A Simple JourneyFrom Grails to Android: A Simple Journey
From Grails to Android: A Simple JourneyAnnyce Davis
776 views126 Folien

Destacado(11)

Devoxx 2015 - Web Application Development using Grails and Docker von Ted Vinke
Devoxx 2015 - Web Application Development using Grails and DockerDevoxx 2015 - Web Application Development using Grails and Docker
Devoxx 2015 - Web Application Development using Grails and Docker
Ted Vinke4.4K views
Connecting Connect with Spring Boot von Vincent Kok
Connecting Connect with Spring BootConnecting Connect with Spring Boot
Connecting Connect with Spring Boot
Vincent Kok1.1K views
From Grails to Android: A Simple Journey von Annyce Davis
From Grails to Android: A Simple JourneyFrom Grails to Android: A Simple Journey
From Grails to Android: A Simple Journey
Annyce Davis776 views
Creating ASTTs The painful truth von Mario García
Creating ASTTs The painful truthCreating ASTTs The painful truth
Creating ASTTs The painful truth
Mario García1.3K views
Continuous Delivery As Code von Alex Soto
Continuous Delivery As CodeContinuous Delivery As Code
Continuous Delivery As Code
Alex Soto1.5K views
Reactive Streams and the Wide World of Groovy von Steve Pember
Reactive Streams and the Wide World of GroovyReactive Streams and the Wide World of Groovy
Reactive Streams and the Wide World of Groovy
Steve Pember1K views

Similar a Mastering Grails 3 Plugins - Greach 2016

Make Your Build Great Again (DroidConSF 2017) von
Make Your Build Great Again (DroidConSF 2017)Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)Jared Burrows
611 views106 Folien
Building Grails Plugins - Tips And Tricks von
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And TricksMike Hugo
7.3K views26 Folien
Gradle von
GradleGradle
GradleReturn on Intelligence
6K views26 Folien
Grails 3.0 Preview von
Grails 3.0 PreviewGrails 3.0 Preview
Grails 3.0 Previewgraemerocher
8.6K views49 Folien
Making the Most of Your Gradle Builds von
Making the Most of Your Gradle BuildsMaking the Most of Your Gradle Builds
Making the Most of Your Gradle BuildsEgor Andreevich
1K views40 Folien
Custom plugin von
Custom pluginCustom plugin
Custom pluginVijay Shukla
69 views30 Folien

Similar a Mastering Grails 3 Plugins - Greach 2016(20)

Make Your Build Great Again (DroidConSF 2017) von Jared Burrows
Make Your Build Great Again (DroidConSF 2017)Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)
Jared Burrows611 views
Building Grails Plugins - Tips And Tricks von Mike Hugo
Building Grails Plugins - Tips And TricksBuilding Grails Plugins - Tips And Tricks
Building Grails Plugins - Tips And Tricks
Mike Hugo7.3K views
Making the Most of Your Gradle Builds von Egor Andreevich
Making the Most of Your Gradle BuildsMaking the Most of Your Gradle Builds
Making the Most of Your Gradle Builds
Egor Andreevich1K views
Grails Connecting to MySQL von ashishkirpan
Grails Connecting to MySQLGrails Connecting to MySQL
Grails Connecting to MySQL
ashishkirpan7.8K views
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English von Sven Haiges
Grails 0.3-SNAPSHOT Presentation WJAX 2006 EnglishGrails 0.3-SNAPSHOT Presentation WJAX 2006 English
Grails 0.3-SNAPSHOT Presentation WJAX 2006 English
Sven Haiges1.4K views
Grails Plugin Best Practices von Burt Beckwith
Grails Plugin Best PracticesGrails Plugin Best Practices
Grails Plugin Best Practices
Burt Beckwith42K views

Más de Alvaro Sanchez-Mariscal

Serverless functions with Micronaut von
Serverless functions with MicronautServerless functions with Micronaut
Serverless functions with MicronautAlvaro Sanchez-Mariscal
1.8K views20 Folien
Asynchronous and event-driven Grails applications von
Asynchronous and event-driven Grails applicationsAsynchronous and event-driven Grails applications
Asynchronous and event-driven Grails applicationsAlvaro Sanchez-Mariscal
2.2K views42 Folien
6 things you need to know about GORM 6 von
6 things you need to know about GORM 66 things you need to know about GORM 6
6 things you need to know about GORM 6Alvaro Sanchez-Mariscal
2.5K views32 Folien
Reactive microservices with Micronaut - GR8Conf EU 2018 von
Reactive microservices with Micronaut - GR8Conf EU 2018Reactive microservices with Micronaut - GR8Conf EU 2018
Reactive microservices with Micronaut - GR8Conf EU 2018Alvaro Sanchez-Mariscal
2.4K views73 Folien
Reactive microservices with Micronaut - Greach 2018 von
Reactive microservices with Micronaut - Greach 2018Reactive microservices with Micronaut - Greach 2018
Reactive microservices with Micronaut - Greach 2018Alvaro Sanchez-Mariscal
14.6K views67 Folien
Practical Spring Cloud von
Practical Spring CloudPractical Spring Cloud
Practical Spring CloudAlvaro Sanchez-Mariscal
867 views31 Folien

Más de Alvaro Sanchez-Mariscal(20)

Creating applications with Grails, Angular JS and Spring Security von Alvaro Sanchez-Mariscal
Creating applications with Grails, Angular JS and Spring SecurityCreating applications with Grails, Angular JS and Spring Security
Creating applications with Grails, Angular JS and Spring Security
Stateless authentication with OAuth 2 and JWT - JavaZone 2015 von Alvaro Sanchez-Mariscal
Stateless authentication with OAuth 2 and JWT - JavaZone 2015Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication for microservices applications - JavaLand 2015 von Alvaro Sanchez-Mariscal
Stateless authentication for microservices applications -  JavaLand 2015Stateless authentication for microservices applications -  JavaLand 2015
Stateless authentication for microservices applications - JavaLand 2015
Stateless token-based authentication for pure front-end applications von Alvaro Sanchez-Mariscal
Stateless token-based authentication for pure front-end applicationsStateless token-based authentication for pure front-end applications
Stateless token-based authentication for pure front-end applications
Workshop: Creating RESTful API’s with Grails and Spring Security (GR8Conf 2014) von Alvaro Sanchez-Mariscal
Workshop: Creating RESTful API’s with Grails and Spring Security (GR8Conf 2014)Workshop: Creating RESTful API’s with Grails and Spring Security (GR8Conf 2014)
Workshop: Creating RESTful API’s with Grails and Spring Security (GR8Conf 2014)
DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014) von Alvaro Sanchez-Mariscal
DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)
DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)

Último

Ports-and-Adapters Architecture for Embedded HMI von
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMIBurkhard Stubert
35 views19 Folien
What is API von
What is APIWhat is API
What is APIartembondar5
15 views15 Folien
nintendo_64.pptx von
nintendo_64.pptxnintendo_64.pptx
nintendo_64.pptxpaiga02016
7 views7 Folien
Winter Projects GDSC IITK von
Winter Projects GDSC IITKWinter Projects GDSC IITK
Winter Projects GDSC IITKSahilSingh368445
416 views60 Folien
Benefits in Software Development von
Benefits in Software DevelopmentBenefits in Software Development
Benefits in Software DevelopmentJohn Valentino
6 views15 Folien
Advanced API Mocking Techniques Using Wiremock von
Advanced API Mocking Techniques Using WiremockAdvanced API Mocking Techniques Using Wiremock
Advanced API Mocking Techniques Using WiremockDimpy Adhikary
5 views11 Folien

Último(20)

Ports-and-Adapters Architecture for Embedded HMI von Burkhard Stubert
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMI
Burkhard Stubert35 views
Advanced API Mocking Techniques Using Wiremock von Dimpy Adhikary
Advanced API Mocking Techniques Using WiremockAdvanced API Mocking Techniques Using Wiremock
Advanced API Mocking Techniques Using Wiremock
Dimpy Adhikary5 views
predicting-m3-devopsconMunich-2023.pptx von Tier1 app
predicting-m3-devopsconMunich-2023.pptxpredicting-m3-devopsconMunich-2023.pptx
predicting-m3-devopsconMunich-2023.pptx
Tier1 app10 views
tecnologia18.docx von nosi6702
tecnologia18.docxtecnologia18.docx
tecnologia18.docx
nosi67026 views
Bootstrapping vs Venture Capital.pptx von Zeljko Svedic
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic16 views
Top-5-production-devconMunich-2023.pptx von Tier1 app
Top-5-production-devconMunich-2023.pptxTop-5-production-devconMunich-2023.pptx
Top-5-production-devconMunich-2023.pptx
Tier1 app10 views
Streamlining Your Business Operations with Enterprise Application Integration... von Flexsin
Streamlining Your Business Operations with Enterprise Application Integration...Streamlining Your Business Operations with Enterprise Application Integration...
Streamlining Your Business Operations with Enterprise Application Integration...
Flexsin 5 views
aATP - New Correlation Confirmation Feature.pptx von EsatEsenek1
aATP - New Correlation Confirmation Feature.pptxaATP - New Correlation Confirmation Feature.pptx
aATP - New Correlation Confirmation Feature.pptx
EsatEsenek1222 views
Transport Management System - Shipment & Container Tracking von Freightoscope
Transport Management System - Shipment & Container TrackingTransport Management System - Shipment & Container Tracking
Transport Management System - Shipment & Container Tracking
Freightoscope 6 views

Mastering Grails 3 Plugins - Greach 2016

  • 2. Álvaro Sánchez-Mariscal Software Engineer Grails Development Team sanchezmariscala@ociweb.com
  • 4. OCI is the new home of Grails More at ociweb.com/grails
  • 6. Creating a Grails 3 plugin $ grails create-plugin myWebPlugin | Plugin created at /private/tmp/myWebPlugin $ grails create-plugin myPlugin -profile plugin | Plugin created at /private/tmp/myPlugin
  • 7. Understanding profiles • A profile defines: • Project’s build.gradle. • Commands: create-domain-class, run-app, etc. • Features: hibernate, json-views, etc. • Skeleton: files and folders.
  • 10. Keep clean • Start with the plugin profile whenever possible. • Remove empty and/or unwanted files/ folders. • Otherwise, the burtbeckwith bot will send you a cleanup pull request!
  • 12. The burtbeckwith bot • Watches messy plugin repos and sends a PR to clean them up. • 14 pull requests in the last 3 months! • Likely hundreds in the last years!
  • 13. The minimal plugin • Folder containing: • build.gradle • src/main/groovy with plugin descriptor. • Empty grails-app folder.
  • 14. The plugin descriptor • A class inside src/main/groovy. Extends grails.plugins.Plugin. • Can override methods to define behaviour in the plugin lifecycle. • Syntax has changed a bit from Grails 2.
  • 16. Plugin configuration • A plugin can define: • Configuration values for the host Grails app. • One of plugin.yml or plugin.groovy. • Configuration for running the plugin as an application, to test it. • application.yml / application.groovy.
  • 17. Excluding content • In the plugin descriptor: • In build.gradle: // resources that are excluded from plugin packaging
 def pluginExcludes = [
 '**/com/example/myplugin/tests/**'
 ] jar {
 exclude 'com/example/myplugin/tests/**/**'
 }
  • 18. Command Line extensions • Use create-script for code generation commands. • Runnable with the Grails CLI. • Use create-command for interacting with a loaded Grails application. • Runnable with the Grails CLI or as a Gradle task.
  • 19. Scripts • Base class: org.grails.cli.profile.commands.script.GroovyScriptCommand import org.grails.cli.interactive.completers.DomainClassCompleter
 
 description( "Generates a controller that performs REST operations" ) {
 usage "grails generate-resource-controller [DOMAIN CLASS]"
 argument name:'Domain Class', description:"The name of the domain class", required:true
 completer DomainClassCompleter
 flag name:'force', description:"Whether to overwrite existing files"
 }
 
 if(args) {
 generateController(*args)
 generateViews(*args)
 generateUnitTest(*args)
 generateFunctionalTest(*args)
 } else {
 error "No domain class specified"
 }
  • 20. Commands import grails.dev.commands.ApplicationCommand
 import grails.dev.commands.ExecutionContext
 
 class MyCommand implements ApplicationCommand {
 
 @Override
 boolean handle(ExecutionContext ctx) {
 def dataSource = applicationContext.getBean(DataSource)
 //Run some SQL...
 
 return true
 }
 
 }
  • 21. Enhancing artefacts import grails.artefact.Enhances
 import groovy.transform.CompileStatic
 
 @Enhances(['Controller', 'Service'])
 @CompileStatic
 trait DateSupport {
 
 Date now() {
 return new Date()
 }
 
 }
  • 23. Modularisation • If your plugin becomes to grow, you might end up creating a monolith. • You can modularise your plugins as you would do with your apps.
  • 25. Modularisation • Benefits: • Optional dependencies. • Smaller JAR files. • Build logic reuse.
  • 26. Modularisation setup • settings.gradle: include ‘myPlugin-core', ‘myPlugin-domain' //etc
  • 27. Modularisation setup • Root build.gradle: allprojects {
 apply plugin:"idea"
 }
 
 subprojects { Project project ->
 ext {
 grailsVersion = project.grailsVersion
 gradleWrapperVersion = project.gradleWrapperVersion
 }
 
 repositories {
 //Common repos
 }
 
 version "1.0.0.M1"
 group "org.grails.plugins"
 
 apply plugin: "org.grails.grails-plugin"
 
 dependencies {
 //Common deps
 }
 }
  • 28. Modularisation setup • Sub-module build.gradle: dependencyManagement {
 imports {
 mavenBom "org.grails:grails-bom:$grailsVersion"
 }
 applyMavenExclusions false
 }
 
 dependencies {
 compile project(":myPlugin-core")
 
 compile "com.example:library:1.0.0"
 }
  • 29. Aggregating Docs task aggregateGroovyDoc(type: Groovydoc) {
 group = JavaBasePlugin.DOCUMENTATION_GROUP
 
 dependsOn subprojects.groovydoc
 source subprojects.groovydoc.source
 destinationDir file("${buildDir}/docs/groovydoc")
 classpath = files(subprojects.groovydoc.classpath)
 groovyClasspath = files(subprojects.groovydoc.groovyClasspath)
 }
  • 31. Artifact publication • Snapshots: • Using the artifactory Gradle plugin. • Published in OJO (oss.jfrog.org). • Releases: • Using the grails-plugin-publish Gradle plugin. • Published in Bintray.
  • 33. • For Snapshots: Build setup artifactory {
 contextUrl = 'http://oss.jfrog.org'
 publish {
 repository {
 repoKey = 'oss-snapshot-local'
 username = bintrayUser
 password = bintrayKey
 }
 defaults {
 publications('maven')
 }
 }
 }
 
 artifactoryPublish {
 dependsOn sourcesJar, javadocJar
 }
  • 34. grailsPublish {
 user = bintrayUser
 key = bintrayKey
 portalUser = pluginPortalUser
 portalPassword = pluginPortalPassword
 
 repo = 'plugins'
 githubSlug = 'alvarosanchez/my-plugin'
 license = 'APACHE 2.0'
 title = "My Plugin"
 desc = "A very cool Grails plugin"
 developers = [
 alvarosanchez: "Alvaro Sanchez-Mariscal"
 ]
 } • For Releases: Build setup
  • 35. Build setup • Define rootProject.name in settings.gradle. • Define credentials in ~/.gradle/gradle.properties.
  • 36. Running it • Snapshot publishing: • Release publishing: $ ./gradlew artifactoryPublish $ ./gradlew publishPlugin notifyPluginPortal
  • 37. Plugin portals • Once your packages are published in your Bintray repo, go to https:// bintray.com/grails/plugins and click on “Include my package”. • Grails 3: http://grails.org/plugins.html • Grails 2: http://grails.org/plugins
  • 39. Testing with a profile • You can create a profile and use it as a TCK for your plugin: • Create test apps from that profile. • Apps come with a set of tests. • Use features to test different configurations.
  • 40. Profile descriptor description: Creates a test app for Spring Security REST plugin
 build:
 excludes:
 - org.grails.grails-core
 dependencies:
 compile:
 - "org.grails.plugins:spring-security-rest:${pluginVersion}"
 - "org.grails:grails-datastore-rest-client:5.0.0.RC3"
 testCompile:
 - "com.codeborne:phantomjsdriver:1.2.1"
 - "org.seleniumhq.selenium:selenium-api:2.47.1"
 - "org.seleniumhq.selenium:selenium-firefox-driver:2.47.1" profile.yml.tmpl
  • 41. Feature descriptor description: First configuration of GORM
 dependencies:
 build:
 - "org.grails.plugins:hibernate4:5.0.0.RC2"
 compile:
 - "org.grails.plugins:hibernate4"
 - "org.hibernate:hibernate-ehcache"
 - "org.grails.plugins:spring-security-rest-gorm:${pluginVersion}"
 runtime:
 - "com.h2database:h2" features/gorm1/feature.yml.tmpl
  • 42. Build setup task generateProfileConfig << {
 copy {
 from 'profile.yml.tmpl'
 into '.'
 rename { String fileName -> fileName.replaceAll '.tmpl', '' }
 expand pluginVersion: project.version
 }
 
 file('features').eachDir { feature ->
 copy {
 from "features/${feature.name}/feature.yml.tmpl"
 into "features/${feature.name}/"
 rename { String fileName -> fileName.replaceAll '.tmpl', '' }
 expand pluginVersion: project.version
 }
 }
 }
 
 compileProfile.dependsOn generateProfileConfig
  • 43. Skeleton • Put in the skeleton all your test files and resources. • You can use features to have different sets of tests, resources and configuration. • Define global configuration values in profile’s root skeleton folder.
  • 44. Test them all! for feature in `ls ../spring-security-rest-testapp-profile/features/`
 do
 grails create-app -profile 
 org.grails.plugins:spring-security-rest-testapp-profile:$pluginVersion 
 -features $feature $feature && cd $feature && ./gradlew check && cd ..
 done
  • 45. Use case: the Spring Security REST plugin