Gretty
Managing 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 Ecosystem
War plugin
Jacoco plugin
Spock 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 test
import geb.spock.GebReportingSpec



class 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 coverage
apply 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 realms
on 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 Products
Lets 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-Boot
gretty {

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
akhikhl@gmail.com
@AndreyHihlovski

Gretty: Managing Web Containers with Gradle

  • 1.
  • 2.
    My story • Joinedweb-app development in 2010
  • 3.
    My story • Joinedweb-app development in 2010 • Moved projects to Maven in 2011
  • 4.
    My story • Joinedweb-app development in 2010 • Moved projects to Maven in 2011 • Moved projects to Gradle in 2013
  • 5.
    Gradle-driven Ecosystem War plugin Jacocoplugin Spock Framework Jetty plugin Tomcat plugin Artifactory plugin Maven plugin Geb Nebula plugins and many more, you choose!
  • 6.
    but wait… • CanI run webapps on Jetty9 with Gradle? • How do I do integration tests? • How do I develop & deliver microservices?
  • 7.
    Super-duper Gradle Plugin thatmakes webapp devs happier Gretty
  • 8.
    Gretty • Hot deployment •Integration tests • Code coverage • Debugger support • Security realms • Multiple Web Containers • Multiple webapps • Product generation • Spring-Boot support 1 year later
  • 9.
    Gretty: getting started plugins{
 id "org.akhikhl.gretty" version "1.2.4"
 } $ gradle appRun
  • 10.
    Gretty tasks # Runit!
 $ gradle appRun # Debug it!
 $ gradle appRunDebug # Run as WAR-file!
 $ gradle appRunWar # Debug as WAR-file!
 $ gradle appRunWarDebug and 40 other tasks!
  • 11.
    Configure Gretty “How dowe change port and context path?” gretty {
 httpPort = 8181
 contextPath = ‘/MyWebApp’
 } $ gradle appRun
  • 12.
    Lets switch Web-Container! gretty{
 servletContainer = ‘tomcat8’
 // ‘tomcat7’, ‘jetty7’, ‘jetty8’, ‘jetty9’
 } $ gradle appRun
  • 13.
    Web-Container runners $ gradleappRun Gretty Plugin Gretty Runner Jetty 7 Gretty Runner Jetty 8 Gretty Runner Jetty 9 Gretty Runner Tomcat 7 Gretty Runner Tomcat 8 servletContainer = ‘tomcat8’
  • 14.
    Hot deployment • Enabledby default • Scans src/main/webapp • Scans main sourceSet • Scans runtime classpath • Scan interval 1 sec
  • 15.
    Configure hot deployment gretty{
 scanInterval = 2 // seconds
 scanDir ‘my/special/code’
 fastReload ‘my/special/resources’
 managedClassReload = true
 // and more properties...
 } $ gradle appRun
  • 16.
  • 17.
    Create integration testtask task test {
 include ‘**/*Test.*’
 exclude ‘**/*IT.*’
 } task integrationTest(type: Test) {
 include ‘**/*IT.*’
 // ... 
 } $ gradle integrationTest
  • 18.
    Geb-driven integration test importgeb.spock.GebReportingSpec
 
 class 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:
 // ...
 }
 }
  • 19.
    Code coverage apply plugin:‘jacoco’
 apply plugin: ‘org.akhikhl.gretty’
 
 // instantiate JacocoReport task $ gradle integrationTest Effect: 
 Jacoco creates coverage reports 
 for server-side and client-side
  • 20.
    Debugger support Lets debugour web-app! gretty {
 debugPort = 5005 // default
 debugSuspend = true // default
 } $ gradle appRunDebug
  • 21.
    Security realms on Jetty: gretty{
 realm ‘auth’
 realmConfigFile ‘jetty-realm.properties’
 } on Tomcat: gretty {
 realm ‘auth’
 realmConfigFile ‘tomcat-users.xml’
 }
  • 22.
    Gretty Farms • Classpathisolation • Configureless • Configurable • Single Sign-On • Debuggable • Integration tests • Code coverage Multiple webapps on the same Web-Container
  • 23.
  • 24.
    Configure Gretty Farm farm{
 webapp project
 webapp “:MyWebService1”
 webapp “:MyWebService2”
 webapp “/somedir/app.war”
 webapp “group:artifact:1.0”
 } $ gradle farmRun
  • 25.
    SSO on GrettyFarm farm {
 singleSignOn = true
 realm ‘auth’
 realmConfigFile ‘jetty-realm.properties’
 }
  • 26.
    Debug Gretty Farm Letsdebug our farm! gretty {
 debugPort = 5005 // default
 debugSuspend = true // default
 } $ gradle farmRunDebug
  • 27.
    Integration Tests onGretty Farm farmBeforeIntegrationTest :myWebService2:integrationTest farmAfterIntegrationTest $ gradle farmIntegrationTest farmIntegrationTest :myWebService1:integrationTest
  • 28.
  • 29.
    Build Gretty Product $gradle buildProduct
 Effects: • Standalone app is generated • Web-Container is included • Web-app packed as WAR • Gretty config saved to JSON
  • 30.
    Configure Gretty Product product{
 webapp project
 webapp “:MyWebService1”
 webapp “:MyWebService2”
 webapp “/somedir/app.war”
 webapp “group:artifact:1.0”
 } $ gradle buildProduct
  • 31.
    Gretty & Spring-Boot gretty{
 springBoot = true
 } $ gradle appRun 
 Effects: • Adds Spring-Boot libraries • Configures embedded Web-Container
  • 32.
    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 ✓
  • 33.
    Gretty is herefor you http://akhikhl.github.io/gretty-doc/ https://github.com/akhikhl/gretty at Gradle Plugin Portal at JCenter at Maven Central
  • 34.
    Thanks for listening! AndreyHihlovskiy akhikhl at GitHub akhikhl@gmail.com @AndreyHihlovski