Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Case Study: Spring Projects on Gradle

cbeams
September 29, 2011

Case Study: Spring Projects on Gradle

Slides from presentation delivered at SpringOne/2GX 2011 in Washington DC. Note that the PDF export here is lossy with regard to style. Follow the instructions at https://github.com/cbeams-archive/spring-on-gradle#to-view-the-slides to view the slides in the original format.

cbeams

September 29, 2011
Tweet

More Decks by cbeams

Other Decks in Programming

Transcript

  1. Who's on Gradle? 7 out of 17 projects > 40%

    All moves made within the last year All have released at least one milestone or GA
  2. Gradle may be nice, but... Maven POMs are critical ∴

    the build must be Maven-based ... right?
  3. apply plugin: 'maven' Poms are: Generated from Gradle metadata Installed

    with jars to local .m2 cache Uploaded to remote Maven repositor(ies)
  4. apply plugin: 'maven' $ gradle install # poms and jars

    to local m2 cache $ gradle uploadArchives # poms and jars to remote repo
  5. Result Single source of dependency metadata Clean, minimal poms Separates

    the concerns of build instructions vs dependency manifest Interoperability with Maven-based builds
  6. Gradle may be nice, but... Many Spring users know Maven

    ∴ the build must be Maven-based ... right?
  7. Assumes Spring users build from source Relatively uncommon But for

    those that do... What is actually required?
  8. What's the status quo? Spring 3 Ant Build Six steps

    - not easy IDE import is complicated We can definitely do better
  9. Maven makes it easy $ git clone $GIT_URL # Import

    poms into m2eclipse / IDEA $ mvn install ...
  10. So does Gradle $ git clone $GIT_URL $ cd spring-project

    $ ./gradlew eclipse # or 'idea' # Import projects into IDE $ ./gradlew install ...
  11. Assertion As long as building from source is simple, works

    with their IDE and interoperates with Maven... ... most users will be happy
  12. Ultimately build system == implementation decision must meet basic requirements

    (like Maven interop) project lead decides what's best
  13. Needs at SpringSource Common deployment infrastructure and procedures Distributed team

    No dedicated CM team or buildmaster Many projects Many users Many Maven repositories Special versioning needs ...
  14. Build Consumer Depends on Maven artifacts Downloads distribution zip Reads

    documentation Probably never thinks about the build system
  15. Build Operator Builds from source (compile, test, etc) May update

    dependency metadata May add new subprojects Needs IDE integration
  16. Build Master Everything an operator does Releases the project Maintains

    the project build Configures CI Writes custom build logic for special needs
  17. Build Operator Make checkout/build/IDE-import dead simple Optimize common use cases

    like compile/test/docs Separate declarative from imperative in build scripts Make the release process as easy as possible Document anything that's not obvious
  18. Build Master Treat imperative build sources like any other project

    Make it editable in the IDE Write tests for the build Keep common build code DRY
  19. Hand-maintained Metadata under Spring (Ant) Build Ivy (ivy.xml) - 'canonical'

    Eclipse (.classpath, .project) IDEA (.iml, .ipr) OSGi (Bundlor template.mf) Maven (pom.xml)
  20. $ mvn clean compile [INFO] Scanning for projects... [INFO] -------------------------------------------------------------

    [INFO] Building Spring Integration Core [INFO] task-segment: [clean, compile] [INFO] ------------------------------------------------------------- [INFO] [clean:clean {execution: default-clean}] [INFO] Deleting directory /Users/cbeams/Work/pax/spring-integration/ [INFO] [resources:resources {execution: default-resources}] [INFO] Using 'UTF8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] Copying 6 resources [INFO] [compiler:compile {execution: default-compile}] [INFO] Compiling 297 source files to /Users/cbeams/Work/pax/spring-i [INFO] ------------------------------------------------------------- [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------- [INFO] Total time: 6 seconds [INFO] Finished at: Wed Nov 24 15:42:19 MST 2010 [INFO] Final Memory: 21M/81M [INFO] -------------------------------------------------------------
  21. $ mvn clean compile [INFO] Scanning for projects... [INFO] -------------------------------------------------------------

    [INFO] Building Spring Integration Core [INFO] task-segment: [clean, compile] [INFO] ------------------------------------------------------------- [INFO] [clean:clean {execution: default-clean}] [INFO] Deleting directory /Users/cbeams/Work/pax/spring-integration/ [INFO] [resources:resources {execution: default-resources}] [INFO] Using 'UTF8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] Copying 6 resources [INFO] [compiler:compile {execution: default-compile}] [INFO] Compiling 297 source files to /Users/cbeams/Work/pax/spring-i [INFO] ------------------------------------------------------------- [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------- [INFO] Total time: 6 seconds [INFO] Finished at: Wed Nov 24 15:42:19 MST 2010 [INFO] Final Memory: 21M/81M [INFO] -------------------------------------------------------------
  22. $ mvn clean compile [INFO] Scanning for projects... [INFO] -------------------------------------------------------------

    [INFO] Building Spring Integration FTP Support [INFO] task-segment: [clean, compile] [INFO] ------------------------------------------------------------- [INFO] [clean:clean {execution: default-clean}] [INFO] Deleting directory /Users/cbeams/Work/pax/spring-integration/ [INFO] [resources:resources {execution: default-resources}] [INFO] Using 'UTF8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] Copying 3 resources [INFO] [compiler:compile {execution: default-compile}] [INFO] Compiling 10 source files to /Users/cbeams/Work/pax/spring-in [WARNING] /Users/cbeams/Work/pax/spring-integration/spring-integrati found : org.apache.commons.net.ftp.FTPFile[] required: F[] [INFO] ------------------------------------------------------------- [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------- [INFO] Total time: 5 seconds [INFO] Finished at: Wed Nov 24 17:10:18 MST 2010 [INFO] Final Memory: 21M/81M [INFO] -------------------------------------------------------------
  23. $ mvn clean compile | wc 351 1626 22858 $

    gradle clean compileJava | wc 113 257 6378
  24. $ mvn clean test | wc 550432 2046401 74486400 $

    gradle clean test | wc 22748 84781 3057486
  25. $ mvn clean test | wc 550432 2046401 74486400 $

    gradle clean test | wc 227 317 8792
  26. Ease of Use Gradle Wrapper Partial builds Task discoverability Support

    source poms gradle help AMQP test exclusions Multi-repository deployment
  27. Get running with Gradle $ git clone --recursive $GIT_URL Cloning

    into spring-integration... remote: Counting objects: 19483, done. remote: Compressing objects: 100% (10387/10387), done. ... $ cd spring-integration && ./gradlew eclipse :spring-integration-core:eclipseClasspath :spring-integration-core:eclipseJdt :spring-integration-core:eclipseProject :spring-integration-core:eclipse :spring-integration-event:eclipseClasspath :spring-integration-event:eclipseJdt :spring-integration-event:eclipseProject :spring-integration-event:eclipse ... BUILD SUCCESSFUL
  28. Wrapper == self-contained builds $ git clone --recursive $GIT_URL $

    cd spring-integration $ ./gradlew build Downloading http://dist.codehaus.org/gradle/gradle-0.9-rc-3-bin.zip ................................................................... ................................................................... Unzipping /Users/cbeams/.gradle/wrapper/dists/gradle-0.9-rc-3-bin.zi Set executable permissions for: /Users/cbeams/.gradle/wrapper/dists/ > Loading ... BUILD SUCCESSFUL
  29. Look at other projects All the Spring projects Gradle itself

    Hibernate Not yet clear what 'idomatic' Gradle looks like
  30. DSL doc vs User Guide Gradle's got a great User

    Guide Explains concepts Walks through certain scenarios Very helpful when getting started
  31. DSL doc vs API doc Gradle's got JavaDoc Often useful

    But it's not enough DSL often relies on Groovy metaprogramming JavaDoc can't cover that
  32. Tooling Gradle UI is there IDEA integrates it Eclipse tooling

    is a must Bash-completion / Gradle shell Project quick-start (archetypes)
  33. Benefits we've gained Clearly modeled and separated concerns Flexibility Concise

    scripts & output Ease of use Fast execution Reusable build sources
  34. Lessons learned Document the build Treat the build like code

    Design the build for user roles and their workflows Total build homogeny == false goal