Gretty: Managing Web Containers with Gradle
-
Upload
andrey-hihlovsky -
Category
Software
-
view
458 -
download
0
Transcript of Gretty: Managing Web Containers with Gradle
GrettyManaging Web-Containers
with Gradle
Gradle Summit 2015 Andrey Hihlovskiy
My story• Joined web-app development in 2010
My story• Joined web-app development in 2010
• Moved projects to Maven in 2011
My story• Joined web-app development in 2010
• Moved projects to Maven in 2011
• Moved projects to Gradle in 2013
Gradle-driven EcosystemWar plugin
Jacoco pluginSpock Framework
Jetty plugin
Tomcat plugin
Artifactory plugin
Maven plugin
Geb
Nebula plugins
and many more, you choose!
but wait…
• Can I run webapps on Jetty9 with Gradle?
• How do I do integration tests?
• How do I develop & deliver microservices?
Super-duper Gradle Plugin that makes webapp devs happier
Gretty
Gretty
• Hot deployment
• Integration tests
• Code coverage
• Debugger support
• Security realms
• Multiple Web Containers
• Multiple webapps
• Product generation
• Spring-Boot support
1 year later
Gretty: getting started
plugins { id "org.akhikhl.gretty" version "1.2.4"}
$ gradle appRun
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!
Configure Gretty
“How do we change port and context path?”
gretty { httpPort = 8181 contextPath = ‘/MyWebApp’}
$ gradle appRun
Lets switch Web-Container!
gretty { servletContainer = ‘tomcat8’ // ‘tomcat7’, ‘jetty7’, ‘jetty8’, ‘jetty9’}
$ gradle appRun
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’
Hot deployment
• Enabled by default • Scans src/main/webapp • Scans main sourceSet • Scans runtime classpath • Scan interval 1 sec
Configure hot deployment
gretty { scanInterval = 2 // seconds scanDir ‘my/special/code’ fastReload ‘my/special/resources’ managedClassReload = true // and more properties...}
$ gradle appRun
Integration tests
beforeIntegrationTest
integrationTest
afterIntegrationTest
$ gradle integrationTest
Create integration test task
task test { include ‘**/*Test.*’ exclude ‘**/*IT.*’}
task integrationTest(type: Test) { include ‘**/*IT.*’ // ... }
$ gradle integrationTest
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: // ... }}
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
Debugger support
Lets debug our web-app!
gretty { debugPort = 5005 // default debugSuspend = true // default}
$ gradle appRunDebug
Security realmson Jetty:
gretty { realm ‘auth’ realmConfigFile ‘jetty-realm.properties’}
on Tomcat:
gretty { realm ‘auth’ realmConfigFile ‘tomcat-users.xml’}
Gretty Farms
• Classpath isolation • Configureless • Configurable • Single Sign-On • Debuggable • Integration tests • Code coverage
Multiple webapps on the same Web-Container
Configureless Gretty Farm
RootProject
MyWebApp
MyWebService
$ gradle farmRun
Configure Gretty Farm
farm { webapp project webapp “:MyWebService1” webapp “:MyWebService2” webapp “/somedir/app.war” webapp “group:artifact:1.0”}
$ gradle farmRun
SSO on Gretty Farm
farm { singleSignOn = true realm ‘auth’ realmConfigFile ‘jetty-realm.properties’}
Debug Gretty Farm
Lets debug our farm!
gretty { debugPort = 5005 // default debugSuspend = true // default}
$ gradle farmRunDebug
Integration Tests on Gretty Farm
farmBeforeIntegrationTest
:myWebService2:integrationTest
farmAfterIntegrationTest
$ gradle farmIntegrationTest
farmIntegrationTest
:myWebService1:integrationTest
Gretty ProductsLets deliver webapps!
Build Gretty Product$ gradle buildProduct
Effects: • Standalone app is generated • Web-Container is included • Web-app packed as WAR • Gretty config saved to JSON
Configure Gretty Product
product { webapp project webapp “:MyWebService1” webapp “:MyWebService2” webapp “/somedir/app.war” webapp “group:artifact:1.0”}
$ gradle buildProduct
Gretty & Spring-Bootgretty { springBoot = true}
$ gradle appRun
Effects: • Adds Spring-Boot libraries • Configures embedded Web-Container
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 ✓
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
Thanks for listening!Andrey Hihlovskiy
akhikhl at GitHub
@AndreyHihlovski