Gradle 2.
Breaking stereotypes
Sergey Morenets, morenets@mail.ru
June, 17 2015
About author
• Works in IT since 2000
• 11 year of Java SE/EE experience
• Regular speaker at Java conferences
• Author of “Development of Java applications” and
“Main errors in Java programming ”books
• Founder of http://it-simulator.com
• 3 years of Gradle usage
Agenda
Agenda
Apache Ant
• Offers extreme flexibility
• Imposes no convention or project standards
• Maintenance headache
• Support Ruby, Groovy, JavaScript, Judoscript,
Jython scripting
Apache Ivy
• Agile dependency manager
• Transitive dependencies
• Ant & Maven integration
• Enhanced support of repositories
Apache Maven
• Support for dependency management
• Standard project layout
• Archetypes
• Hard customization
• Declarative approach
• Plugin execution framework
Build systems
Apache Maven
Ant plugin
Groovy plugin
Echo plugin
Gradle
Maven
Gradle
Gradle
Maven
Gradle
Issue #1. XML
• Large and complex files are hard to understand
• Hierarchical structure limits the expressiveness
of the format
• Good format for the data and complex for the flow
Hans Dockter
• Founder of Gradle and Gradleware
• 13 years of experience as a software developer,
team leader, architect, trainer, and mentor
• Previously worked at Jboss and founded Jboss-IDE
• Holds a Diploma in Physics with a minor in Computer
Science
• Admirer of domain-driven-design
Slogan
• Make the impossible possible
• Make the possible easy
• Make the easy elegant
Solution #1. Groovy
• An agile and dynamic language for the Java
Virtual Machine
• Makes modern programming features available to
Java developers with almost-zero learning curve
• Provides the ability to statically type
check and statically compile your code for
robustness and performance
• Share base syntax, type system, packages
hierarchy with Java
• Every Gradle build file is Groovy script
Gradle
Gradle
• Development started in Apr 2008
• Current version 2.4 released in May 2015
• Default build tool for Android OS
Gradle overview
• A flexible general purpose build tool
• Programming tool
• Declarative builds and build-by-convention
• Multi-project support
• Powerful dependency management
Development
Version Release date
Maven 1.0 2004
Maven 2.0 2005
Maven 3.0 2010
Maven 3.1 2013
Maven 3.3 2015
Development
Version Release date
Gradle 0.7 2009
Gradle 1.0 2012
Gradle 1.5 2013
Gradle 2.0 2014
Gradle 2.4 2015
Build structure
Hello world
$ gradle helloWorld
build.gradle
Maven pom
Sample project
Sample project
Custom task
• Writes audit information at the end of the build
• Audit information includes project name and build
timestamp
• Audit files are located in the separate folder
Custom task
Custom task
Cache everything
• Remote metadata and artifacts
• Transitive dependency resolution
• Build execution plan
• Plugin inputs and outputs
• Test results
Daemon
• Improves startup and execution time of Gradle
• Initial Gradle command forks daemon process
• Subsequent Gradle commands reuse the build
daemon
• If daemon is currently busy then new daemon
process is started on-demand
• Useful for small tasks execution
• Expires after 3 hours of idle time
gradle.properties
• org.gradle.daemon=true
• org.gradle.configureondemand=true
• org.gradle.parallel=true
• org.gradle.java.home=C:Program
FilesJavajdk1.8.0_45
• org.gradle.jvmargs=-Xmx100m
Test execution
# of threads H2 – time(sec) MySQL – time(sec)
1 24,4 27,5
2 31,1 36,9
4 46,2 51,1
8 71,1 80,5
Plugin
• Reusable pieces of build logic
• Can be used in different projects/builds
Plugin portal
Custom plugin
gradle helloWorld
Maven
Gradle
Integrates with everything
Gradle and Maven
Comparison
• Maven 3.3.3
• Gradle 2.4
• JDK 1.8.0.45
• Intel Core i7, 4 cores, 16 GB
• Multi-project and single project builds
• Optimized and default modes
Multi-project
Operation Gradle
(opt)
Gradle
(daemon)
Gradle(no
daemon)
Maven Maven
(parall)
Build(sec) 8,03 10,73 13,68 12,40 13,02
Inc build(sec) 1,92 2,16 4,74 4,62 4,64
Clean(sec) 1,03 1,20 2,77 1,71 1,70
Gradle
Optimized Not optimized
Maven
Optimized Not optimized
Single project
Operation Gradle
(opt)
Gradle
(daemon)
Gradle(no
daemon)
Maven Maven
(parall)
Build(sec) 1,41 1,46 4,55 2,38 2,37
Inc build(sec) 0,95 1,01 3,27 0,88 0,86
Clean(sec) 0,89 0,95 2,68 0,24 0,19
Maven converter
• maven2Gradle is obsolete now
• Build init plugin converts:
o POM settings
o Dependencies
o Properties
o Java compiler settings
o Single- and multi-project settings
o Packaging of sources and tests
Repositories
Maven Scope
Maven Scope
Configurations
Version management
Version management
Profiles
• build.gradle
• dev-profile.gradle
• test-profile.gradle
• $ gradle –Pprofile=dev build
Skip tasks
• $ gradle -PskipTests
Caching
• Gradle caches all compiles scripts by default
• Compiled scripts are put into .gradle folder
• Gradle uses compiled version if the script hasn’t
changed
• --recompile-scripts option discards cache
Wrapper
• Preferred way of starting a Gradle build
• Gradle will be automatically downloaded via
wrapper
• Includes shell script
• Useful for CI tasks
Pros
• Native Java/Scala/Groovy support
• Ant/Maven/Ivy integration
• Full IDE support
• Flexible DSL
• Multiple third-party plugins(70+)
• Declarative & imperative approaches
• Rapid development
• Performance
Cons
• Compilation & run-time issues
• Larger learning curve
• Less community & industry support
Future
Practice
• https://github.com/hibernate/hibernate-orm
• https://github.com/SpringSource/spring-framework
• https://github.com/gradle/gradle
Q&A
• Sergey Morenets, morenets@mail.ru

Gradle 2.Breaking stereotypes