gretty: managing web containers with gradle
TRANSCRIPT
![Page 1: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/1.jpg)
GrettyManaging Web-Containers
with Gradle
Gradle Summit 2015 Andrey Hihlovskiy
![Page 2: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/2.jpg)
My story• Joined web-app development in 2010
![Page 3: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/3.jpg)
My story• Joined web-app development in 2010
• Moved projects to Maven in 2011
![Page 4: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/4.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/5.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/6.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/7.jpg)
Super-duper Gradle Plugin that makes webapp devs happier
Gretty
![Page 8: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/8.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/9.jpg)
Gretty: getting started
plugins { id "org.akhikhl.gretty" version "1.2.4"}
$ gradle appRun
![Page 10: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/10.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/11.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/12.jpg)
Lets switch Web-Container!
gretty { servletContainer = ‘tomcat8’ // ‘tomcat7’, ‘jetty7’, ‘jetty8’, ‘jetty9’}
$ gradle appRun
![Page 13: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/13.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/14.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/15.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/16.jpg)
Integration tests
beforeIntegrationTest
integrationTest
afterIntegrationTest
$ gradle integrationTest
![Page 17: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/17.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/18.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/19.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/20.jpg)
Debugger support
Lets debug our web-app!
gretty { debugPort = 5005 // default debugSuspend = true // default}
$ gradle appRunDebug
![Page 21: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/21.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/22.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/23.jpg)
Configureless Gretty Farm
RootProject
MyWebApp
MyWebService
$ gradle farmRun
![Page 24: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/24.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/25.jpg)
SSO on Gretty Farm
farm { singleSignOn = true realm ‘auth’ realmConfigFile ‘jetty-realm.properties’}
![Page 26: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/26.jpg)
Debug Gretty Farm
Lets debug our farm!
gretty { debugPort = 5005 // default debugSuspend = true // default}
$ gradle farmRunDebug
![Page 27: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/27.jpg)
Integration Tests on Gretty Farm
farmBeforeIntegrationTest
:myWebService2:integrationTest
farmAfterIntegrationTest
$ gradle farmIntegrationTest
farmIntegrationTest
:myWebService1:integrationTest
![Page 28: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/28.jpg)
Gretty ProductsLets deliver webapps!
![Page 29: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/29.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/30.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/31.jpg)
Gretty & Spring-Bootgretty { springBoot = true}
$ gradle appRun
Effects: • Adds Spring-Boot libraries • Configures embedded Web-Container
![Page 32: Gretty: Managing Web Containers with Gradle](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/32.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/33.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022052301/55b6e38ebb61eb6c268b4780/html5/thumbnails/34.jpg)
Thanks for listening!Andrey Hihlovskiy
akhikhl at GitHub
@AndreyHihlovski