Gretty: Managing Web Containers with Gradle

34
Gretty Managing Web-Containers with Gradle Gradle Summit 2015 Andrey Hihlovskiy

Transcript of Gretty: Managing Web Containers with Gradle

Page 1: Gretty: Managing Web Containers with Gradle

GrettyManaging Web-Containers

with Gradle

Gradle Summit 2015 Andrey Hihlovskiy

Page 2: Gretty: Managing Web Containers with Gradle

My story• Joined web-app development in 2010

Page 3: Gretty: Managing Web Containers with Gradle

My story• Joined web-app development in 2010

• Moved projects to Maven in 2011

Page 4: Gretty: Managing Web Containers with Gradle

My story• Joined web-app development in 2010

• Moved projects to Maven in 2011

• Moved projects to Gradle in 2013

Page 5: Gretty: Managing Web Containers with Gradle

Gradle-driven EcosystemWar plugin

Jacoco pluginSpock Framework

Jetty plugin

Tomcat plugin

Artifactory plugin

Maven plugin

Geb

Nebula plugins

and many more, you choose!

Page 6: Gretty: Managing Web Containers with Gradle

but wait…

• Can I run webapps on Jetty9 with Gradle?

• How do I do integration tests?

• How do I develop & deliver microservices?

Page 7: Gretty: Managing Web Containers with Gradle

Super-duper Gradle Plugin that makes webapp devs happier

Gretty

Page 8: Gretty: Managing Web Containers with Gradle

Gretty

• Hot deployment

• Integration tests

• Code coverage

• Debugger support

• Security realms

• Multiple Web Containers

• Multiple webapps

• Product generation

• Spring-Boot support

1 year later

Page 9: Gretty: Managing Web Containers with Gradle

Gretty: getting started

plugins { id "org.akhikhl.gretty" version "1.2.4"}

$ gradle appRun

Page 10: Gretty: Managing Web Containers with Gradle

Gretty tasks# Run it!$ gradle appRun

# Debug it!$ gradle appRunDebug

# Run as WAR-file!$ gradle appRunWar

# Debug as WAR-file!$ gradle appRunWarDebug

and 40 other tasks!

Page 11: Gretty: Managing Web Containers with Gradle

Configure Gretty

“How do we change port and context path?”

gretty { httpPort = 8181 contextPath = ‘/MyWebApp’}

$ gradle appRun

Page 12: Gretty: Managing Web Containers with Gradle

Lets switch Web-Container!

gretty { servletContainer = ‘tomcat8’ // ‘tomcat7’, ‘jetty7’, ‘jetty8’, ‘jetty9’}

$ gradle appRun

Page 13: Gretty: Managing Web Containers with Gradle

Web-Container runners$ gradle appRun

Gretty Plugin

Gretty Runner Jetty 7

Gretty Runner Jetty 8

Gretty Runner Jetty 9

Gretty Runner Tomcat 7

Gretty Runner Tomcat 8

servletContainer = ‘tomcat8’

Page 14: Gretty: Managing Web Containers with Gradle

Hot deployment

• Enabled by default • Scans src/main/webapp • Scans main sourceSet • Scans runtime classpath • Scan interval 1 sec

Page 15: Gretty: Managing Web Containers with Gradle

Configure hot deployment

gretty { scanInterval = 2 // seconds scanDir ‘my/special/code’ fastReload ‘my/special/resources’ managedClassReload = true // and more properties...}

$ gradle appRun

Page 16: Gretty: Managing Web Containers with Gradle

Integration tests

beforeIntegrationTest

integrationTest

afterIntegrationTest

$ gradle integrationTest

Page 17: Gretty: Managing Web Containers with Gradle

Create integration test task

task test { include ‘**/*Test.*’ exclude ‘**/*IT.*’}

task integrationTest(type: Test) { include ‘**/*IT.*’ // ... }

$ gradle integrationTest

Page 18: Gretty: Managing Web Containers with Gradle

Geb-driven integration testimport geb.spock.GebReportingSpecclass WebAppIT extends GebReportingSpec { private static String uri void setupSpec() { uri = System.getProperty(‘gretty.baseURI’) } def ‘should get home page’() { when: go “${uri}/index.html” then: // ... }}

Page 19: Gretty: Managing Web Containers with Gradle

Code coverageapply plugin: ‘jacoco’apply plugin: ‘org.akhikhl.gretty’// instantiate JacocoReport task

$ gradle integrationTest

Effect: Jacoco creates coverage reports for server-side and client-side

Page 20: Gretty: Managing Web Containers with Gradle

Debugger support

Lets debug our web-app!

gretty { debugPort = 5005 // default debugSuspend = true // default}

$ gradle appRunDebug

Page 21: Gretty: Managing Web Containers with Gradle

Security realmson Jetty:

gretty { realm ‘auth’ realmConfigFile ‘jetty-realm.properties’}

on Tomcat:

gretty { realm ‘auth’ realmConfigFile ‘tomcat-users.xml’}

Page 22: Gretty: Managing Web Containers with Gradle

Gretty Farms

• Classpath isolation • Configureless • Configurable • Single Sign-On • Debuggable • Integration tests • Code coverage

Multiple webapps on the same Web-Container

Page 23: Gretty: Managing Web Containers with Gradle

Configureless Gretty Farm

RootProject

MyWebApp

MyWebService

$ gradle farmRun

Page 24: Gretty: Managing Web Containers with Gradle

Configure Gretty Farm

farm { webapp project webapp “:MyWebService1” webapp “:MyWebService2” webapp “/somedir/app.war” webapp “group:artifact:1.0”}

$ gradle farmRun

Page 25: Gretty: Managing Web Containers with Gradle

SSO on Gretty Farm

farm { singleSignOn = true realm ‘auth’ realmConfigFile ‘jetty-realm.properties’}

Page 26: Gretty: Managing Web Containers with Gradle

Debug Gretty Farm

Lets debug our farm!

gretty { debugPort = 5005 // default debugSuspend = true // default}

$ gradle farmRunDebug

Page 27: Gretty: Managing Web Containers with Gradle

Integration Tests on Gretty Farm

farmBeforeIntegrationTest

:myWebService2:integrationTest

farmAfterIntegrationTest

$ gradle farmIntegrationTest

farmIntegrationTest

:myWebService1:integrationTest

Page 28: Gretty: Managing Web Containers with Gradle

Gretty ProductsLets deliver webapps!

Page 29: Gretty: Managing Web Containers with Gradle

Build Gretty Product$ gradle buildProduct

Effects: • Standalone app is generated • Web-Container is included • Web-app packed as WAR • Gretty config saved to JSON

Page 30: Gretty: Managing Web Containers with Gradle

Configure Gretty Product

product { webapp project webapp “:MyWebService1” webapp “:MyWebService2” webapp “/somedir/app.war” webapp “group:artifact:1.0”}

$ gradle buildProduct

Page 31: Gretty: Managing Web Containers with Gradle

Gretty & Spring-Bootgretty { springBoot = true}

$ gradle appRun

Effects: • Adds Spring-Boot libraries • Configures embedded Web-Container

Page 32: Gretty: Managing Web Containers with Gradle

Gretty & Spring-Boot• Gretty Configuration & Spring-Boot ✓

• Gretty Tasks & Spring-Boot ✓

• Multiple Web-Containers & Spring-Boot ✓

• Hot deployment & Spring-Boot ✓

• Integration tests & Spring-Boot ✓

• Gretty Farms & Spring-Boot ✓

• Gretty Products & Spring-Boot ✓

Page 33: Gretty: Managing Web Containers with Gradle

Gretty is here for you

http://akhikhl.github.io/gretty-doc/

https://github.com/akhikhl/gretty

at Gradle Plugin Portal

at JCenter

at Maven Central

Page 34: Gretty: Managing Web Containers with Gradle

Thanks for listening!Andrey Hihlovskiy

akhikhl at GitHub

[email protected]

@AndreyHihlovski