SlideShare a Scribd company logo
FASTER JAVA EE
BUILDS WITH GRADLE
Ryan Cuprak
About
Ryan Cuprak
• @ctjava
• rcuprak@gmail.com
• http://www.cuprak.info
• https://www.linkedin.com/in/rcuprak
Introducing Gradle
• Open source build automation system
• Apache 2.0 License
• Builds upon Apache Ant and Maven
• First released in 2007
• Uses a Groovy-based DSL (not XML)
• Uses directed acyclic graph to determine build order
• Supports multiple languages: Java, C++, C, etc.
• Rich plug-in architecture
• Convention over configuration but easily
customized/adapted
Introducing Gradle
• Build file can be versioned like dependencies.
Ever run Ant 1.9 file with Ant 1.6?
• Background daemon reduces build-time
• Supports incremental builds
• Built-in profiling support
• Build projects in parallel and some tasks*
• Built-in Ant/Maven integration
• Supported central repositories:
• Maven Central
• Jcenter
• Ivy
Build System Evolution
Ant
Maven
Gradle2004
2009
2000
Gradle versus Maven
Feature Gradle Maven
Fully configurable DAG ✅ ❌
Task Exclusion ✅ ❌
Dry Run ✅ ❌
Advanced Task Ordering ✅ ❌
Custom Distributions ✅ ❌
Repository Aware Cache ✅ ❌
Version Conflict Resolution ✅ ❌
File Based Dependencies ✅ ❌
Build Comparison ✅ ❌
Custom Dependency Scopes ✅ ❌
ReplaceByRules ✅ ❌
Why Gradle?
Questions
1. Do you need to learn Groovy?
No (Good idea)
2. Do you need to completely refactor your code base?
No
3. Do you need additional IDE plugins?
Maybe
4. Do you need to change your build process?
Depends
5. Do you need to port your entire build system over?
No – can port over individual modules
6. Can you embed custom Ant logic?
Yes
Questions…
7. Must all dependencies originate from a repository?
No
8. Can artifacts be pushed to a repository?
Yes
9. Can Jenkins initiate Gradle builds?
Yes
Why Gradle for Java EE?
• Java EE projects are:
• Large
• Complex
• Contain many dependencies
• Ant lacks dependency management
• Large Ant files are a nightmare to debug
• Maven isn’t flexible
• Custom plugins aren’t the solution
• Evolving slowly
Installation
• Installation similar to Ant/Maven
• Download and install from gradle.org
• Set environment variables:
• GRADLE_HOME
• PATH (to GRADLE_HOME/bin)
• gradle = ant = mvn
Key Gradle Files
Build file build.gradle
Configuration settings settings.gradle
Local settings ~/.gradle/gradle.properties
Local repository (project)/.gradle
build.gradle = pom.xml = build.xml
Gradle Daemon
• Gradle daemon is enabled by default
• Disable for continuous build environments!
• Displaying status
gradle –status
• Stopping daemon:
gradle –stop
• Disabling daemon:
• Add org.gradle.daemon=false to ~/.gradle
Project Creation
To start a new project:
• gradle init – creates a new project
• Uses pom.xml if present.
• Import multi-model projects
• Optionally specify –type <type>
• java-library
• scala-library
• groovy-library
• basic (default) – no src directories created.
• Central repository defaults to jcenter()
https://bintray.com/bintray/jcenter
Project Creation…
gradle init --type java-library
Default Project Layout
src
main
resources
test
java
resources
build.gradle
settings.gradle
java
project
Initial Gradle File
Command line – listing tasks
gradle –q tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all
projects that depend on it.
buildNeeded - Assembles and tests this project and all projects
it depends on.
classes - Assembles classes 'main'.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles classes 'test'.
Tasks Continued…
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the
main source code.
Tasks Continue…
Help tasks
----------
components - Displays the components produced by root
project 'scratch'. [incubating]
dependencies - Displays all dependencies declared in root
project 'scratch'.
dependencyInsight - Displays the insight into a specific
dependency in root project 'scratch'.
help - Displays a help message.
model - Displays the configuration model of root project
'scratch'. [incubating]
projects - Displays the sub-projects of root project 'scratch'.
properties - Displays the properties of root project 'scratch'.
tasks - Displays the tasks runnable from root project 'scratch'.
Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.
Sample Gradle
gradle build
src
build
scratch-1.0-SNAPSHOT.jar
libs
project
Output
Projects versus Tasks
Project 1 Project 2
Project 3
Task 1
Task 3
Task 2
Depends on
Task 1
Task 2
Depends on
Task 1
Task 3
Task 2
Depends on
Task 3
Depends on
Understanding Gradle Build File
org.gradle.api.Project
apply(options: Map<String,?>)
buildscript(config: Closure)
dependencies(config: Closure)
configurations(config: Closure)
getDependencies()
getConfigurations()
getAnt()
getName()
getDescription()
getGroup()
getPath()
getVersion()
getLogger()
setDescription(description: String)
setVersion(version: Object)
file(path: Object)
task(args: Map<String,?>,name: String)
Within a Gradle file, project implicit.
Above could be written as:
project.apply plugin: ‘java’
Understanding Gradle Tasks
org.gradle.api.Task
dependsOn(tasks: Object…)
doFirst(action: Closure)
doLast(action: Closure)
getActions()
getInputs()
getOutputs()
getAnt()
getDescription()
getEnabled()
getGroup()
setDescription(description: String)
setEnabled(enabled: boolean)
setGroup(group: String)
Tasks are built on the Task object.
Defining Tasks
Task Dependencies
Grouping Tasks
Group Tasks
Custom Group
Plugins
Plugin ID Automatically
Applies
Works With Description
java java-base Java compilation/testing
application java,distribution
ear java Java EE Support
maven java,war Maven publishing
war java Assembles WAR files
java-library-
distribution
java, distribution Support for tar/zip
distributions for Java
library.
idea java Generates IDEA files
eclipse java,groovy,
scala
Generates Eclipse files
Standard: https://docs.gradle.org/current/userguide/standard_plugins.html
Third party: https://plugins.gradle.org
Multi-Module Projects
admin-web
model
myApp
web
mobile-app
build.gradle
gradle.properties
admin-web
model
myApp
web
mobile-app
build.gradle
gradle.properties
master
Hierarchical Layout Flat Layout
Hierarchical Layout: Example Project
ctjava
build.gradle
settings.gradle
ctcore
build.gradle
settings.gradle
ctweb
build.gradle
settings.gradle
migrate
build.gradle
settings.gradle
Hierarchical Layout: Top Level
build.gradle gradle.settings
ctjava
Hierarchical Layout: Second Level
• gradle.settings for ctcore/migrate/ctweb:
rootProject.name = 'ctjava’
• migrate/ctweb dependencies on ctcore:
compile project (':ctcore’)
IDE Support
IDE Separate Plugin Java EE Support
IDEA (free) No Yes
IDEA (paid) No Yes
NetBeans Yes Depends
Eclipse Yes Yes
Eclipse Gradle Support
http://download.eclipse.org/buildship/updates/e46/releases/1.0
NetBeans Gradle Support
Multi-project Java EE projects not recognized.
[WAR] NetBean Web App – Ant Build
File System File System
[WAR] NetBeans Web App - Gradle
Java Source
directories
WAR Plugin
Local JARs
[WAR] NetBeans Web App – Gradle…
Web resource
directory
Java EE
Dependencies
Local JAR
WAR Plugin Configuration
Configuration Description
from Adds a file-set to the root of the archive
webInf Adds a file-set to the WEB-INF dir.
classpath Adds a file-set to the WEB-INF/lib dir
webAppDirName The name of the web application source directory, relative
to the project directory.
webXml Copies a file to WEB-INF/web.xml
JavaScript Minification
Minification
Output
Google Minifier
JavaScript Minification…
Extend JavaExec Task to invoke Minifier
JavaScript Minification…
gradle -PjsOptimize=true build
Generating JPA Meta-Model
Create custom plugin to run Java Annotation Processor:
implementation-class=JavaAptPlugin
Custom Annotation Processor
Custom Annotation Processor
Custom Annotation Processor:
Build Plugin
Exclude everything
but JPA entities
EAR Projects
Project Output
EAR Project
Provided Scope – Non-WAR Projects
• providedCompile is a configuration on WAR plugin.
• Non-WAR projects must add a custom scope.
jaxb Code Generation
POJOxsd
Generating JAX-WS Client
• Generate JAX-WS client for WSDL using wsimport
• Plugin:
https://plugins.gradle.org/plugin/me.seeber.wsimport
• Generated source code:
• Build/generated-src/wsimport
Generating JAX-WS Client
https://plugins.gradle.org/plugin/me.seeber.wsimport
Generating JAX-WS Client
Generated Source Code
Docker
• Build Docker images from project output:
• Transmode/gradle-docker - http://tinyurl.com/k7o7nab
• Build/publish docker files from build script – not Dockerfile
• bmuschko/gradle-docker-plugin - http://tinyurl.com/hg4q6jr
• docker-remote-api – interacts with Docker via remote API
• docker-java-application – creates/pushes docker images for java
applications
• Run Docker containers during build
• palantir/gradle-docker - http://tinyurl.com/hpw853h
• docker – building and pushing docker images
• docker-compose - populating placeholders in a docker-compose
template
• docker-run – starting/stopping/status on named images
Building Docker Images
Simple Docker Example – Run Container
Available Tasks:
• dockerRun
• dockerStop
• dockerRunStatus
• dockerRemoveContainer
Docker & Testing
• Launch Postgresql Docker container before unit tests
execute
• Test cleanup:
• Leave container running if any tests fail
• Destroy container if tests succeed
Docker & Testing
Docker Database Testing
Parameter Substitution: persistence.xml
Parameter Substitution: build.gradle
Testing with Arquillian/Selenium
Misc
• View Dependencies:
gradle -q ctweb:dependencies
• Build GUI:
gradle –gui
• Profiling:
gradle –profile
• Dry-run
gradle –m build
Q&A

More Related Content

What's hot (20)

PPTX
Java script nirvana in netbeans [con5679]
Ryan Cuprak
 
PPTX
Spring Framework 3.2 - What's New
Sam Brannen
 
PPTX
Faster Java EE Builds with Gradle
Ryan Cuprak
 
PPTX
Workshop Framework(J2EE/OSGi/RCP)
Summer Lu
 
PDF
Developing Plug-Ins for NetBeans
elliando dias
 
PPTX
Java EE 8 Update
Ryan Cuprak
 
PDF
Enabling White-Box Reuse in a Pure Composition Language
elliando dias
 
PDF
Web application development using Play Framework (with Java)
Saeed Zarinfam
 
PDF
Apache Lucene for Java EE Developers
Virtual JBoss User Group
 
PPTX
Why Play Framework is fast
Legacy Typesafe (now Lightbend)
 
PPTX
Full stack development with node and NoSQL - All Things Open - October 2017
Matthew Groves
 
PDF
Gradle - Build System
Jeevesh Pandey
 
PDF
Apache DeltaSpike the CDI toolbox
Antoine Sabot-Durand
 
PDF
Play Framework and Activator
Kevin Webber
 
PPTX
JSF2
Alex Tumanoff
 
PDF
Play vs Grails Smackdown - Devoxx France 2013
Matt Raible
 
PPTX
Hybrid Mobile Development with Apache Cordova and
Ryan Cuprak
 
PDF
Microservices - java ee vs spring boot and spring cloud
Ben Wilcock
 
PPTX
Overview of PaaS: Java experience
Alex Tumanoff
 
PDF
Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI
Mario-Leander Reimer
 
Java script nirvana in netbeans [con5679]
Ryan Cuprak
 
Spring Framework 3.2 - What's New
Sam Brannen
 
Faster Java EE Builds with Gradle
Ryan Cuprak
 
Workshop Framework(J2EE/OSGi/RCP)
Summer Lu
 
Developing Plug-Ins for NetBeans
elliando dias
 
Java EE 8 Update
Ryan Cuprak
 
Enabling White-Box Reuse in a Pure Composition Language
elliando dias
 
Web application development using Play Framework (with Java)
Saeed Zarinfam
 
Apache Lucene for Java EE Developers
Virtual JBoss User Group
 
Why Play Framework is fast
Legacy Typesafe (now Lightbend)
 
Full stack development with node and NoSQL - All Things Open - October 2017
Matthew Groves
 
Gradle - Build System
Jeevesh Pandey
 
Apache DeltaSpike the CDI toolbox
Antoine Sabot-Durand
 
Play Framework and Activator
Kevin Webber
 
Play vs Grails Smackdown - Devoxx France 2013
Matt Raible
 
Hybrid Mobile Development with Apache Cordova and
Ryan Cuprak
 
Microservices - java ee vs spring boot and spring cloud
Ben Wilcock
 
Overview of PaaS: Java experience
Alex Tumanoff
 
Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI
Mario-Leander Reimer
 

Viewers also liked (20)

PDF
Gradle
Andrii Khaisin
 
PPTX
Jms deep dive [con4864]
Ryan Cuprak
 
PPTX
Top 50 java ee 7 best practices [con5669]
Ryan Cuprak
 
PPTX
50 EJB 3 Best Practices in 50 Minutes - JavaOne 2014
Ryan Cuprak
 
PPTX
Containerless in the Cloud with AWS Lambda
Ryan Cuprak
 
PPTX
Dev ecosystem v1.1
Andrii Khaisin
 
PDF
Gradle and build systems for C language
Juraj Michálek
 
PPTX
JavaOne 2013: Organizing Your Local Community
Ryan Cuprak
 
PDF
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
ZeroTurnaround
 
PDF
Docker containerization cookbook
Pascal Louis
 
PPTX
JavaFX Versus HTML5 - JavaOne 2014
Ryan Cuprak
 
PDF
CDI 2.0 is upon us Devoxx
Antoine Sabot-Durand
 
PDF
不只自動化而且更敏捷的Android開發工具 gradle mopcon
sam chiu
 
PDF
Gradle - time for a new build
Igor Khotin
 
PPTX
Combining R With Java For Data Analysis (Devoxx UK 2015 Session)
Ryan Cuprak
 
PDF
Performance optimization for Android
Arslan Anwar
 
PPTX
Batching and Java EE (jdk.io)
Ryan Cuprak
 
PPT
Spring + JPA + DAO Step by Step
Guo Albert
 
PDF
Gradle by Example
Eric Wendelin
 
PPTX
Gradle
Jadson Santos
 
Jms deep dive [con4864]
Ryan Cuprak
 
Top 50 java ee 7 best practices [con5669]
Ryan Cuprak
 
50 EJB 3 Best Practices in 50 Minutes - JavaOne 2014
Ryan Cuprak
 
Containerless in the Cloud with AWS Lambda
Ryan Cuprak
 
Dev ecosystem v1.1
Andrii Khaisin
 
Gradle and build systems for C language
Juraj Michálek
 
JavaOne 2013: Organizing Your Local Community
Ryan Cuprak
 
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
ZeroTurnaround
 
Docker containerization cookbook
Pascal Louis
 
JavaFX Versus HTML5 - JavaOne 2014
Ryan Cuprak
 
CDI 2.0 is upon us Devoxx
Antoine Sabot-Durand
 
不只自動化而且更敏捷的Android開發工具 gradle mopcon
sam chiu
 
Gradle - time for a new build
Igor Khotin
 
Combining R With Java For Data Analysis (Devoxx UK 2015 Session)
Ryan Cuprak
 
Performance optimization for Android
Arslan Anwar
 
Batching and Java EE (jdk.io)
Ryan Cuprak
 
Spring + JPA + DAO Step by Step
Guo Albert
 
Gradle by Example
Eric Wendelin
 
Ad

Similar to Faster java ee builds with gradle [con4921] (20)

PDF
Gradle - Build system evolved
Bhagwat Kumar
 
PPTX
Gradle 2.Write once, builde everywhere
Strannik_2013
 
PDF
OpenCms Days 2012 - Developing OpenCms with Gradle
Alkacon Software GmbH & Co. KG
 
PDF
Android gradle-build-system-overview
Kevin He
 
PDF
Gradle ex-machina
Andres Almiray
 
PDF
Andres Almiray - Gradle Ex Machina - Codemotion Rome 2019
Codemotion
 
PPTX
Gradle.Enemy at the gates
Strannik_2013
 
PDF
Introduction to gradle
NexThoughts Technologies
 
PPTX
Gradle 2.breaking stereotypes.
Stfalcon Meetups
 
PDF
Make Your Build Great Again (DroidConSF 2017)
Jared Burrows
 
PPT
An introduction to maven gradle and sbt
Fabio Fumarola
 
PDF
Gradle
Han Yin
 
PPTX
Exploring the power of Gradle in android studio - Basics & Beyond
Kaushal Dhruw
 
ODP
Gradle: The Build System you have been waiting for!
Corneil du Plessis
 
PPTX
Hands on Gradle
Mushfekur Rahman
 
PDF
ICONUK 2015 - Gradle Up!
René Winkelmeyer
 
PDF
Gradle - the Enterprise Automation Tool
Izzet Mustafaiev
 
PDF
What's new in Gradle 4.0
Eric Wendelin
 
PDF
Serverless Container with Source2Image
QAware GmbH
 
Gradle - Build system evolved
Bhagwat Kumar
 
Gradle 2.Write once, builde everywhere
Strannik_2013
 
OpenCms Days 2012 - Developing OpenCms with Gradle
Alkacon Software GmbH & Co. KG
 
Android gradle-build-system-overview
Kevin He
 
Gradle ex-machina
Andres Almiray
 
Andres Almiray - Gradle Ex Machina - Codemotion Rome 2019
Codemotion
 
Gradle.Enemy at the gates
Strannik_2013
 
Introduction to gradle
NexThoughts Technologies
 
Gradle 2.breaking stereotypes.
Stfalcon Meetups
 
Make Your Build Great Again (DroidConSF 2017)
Jared Burrows
 
An introduction to maven gradle and sbt
Fabio Fumarola
 
Gradle
Han Yin
 
Exploring the power of Gradle in android studio - Basics & Beyond
Kaushal Dhruw
 
Gradle: The Build System you have been waiting for!
Corneil du Plessis
 
Hands on Gradle
Mushfekur Rahman
 
ICONUK 2015 - Gradle Up!
René Winkelmeyer
 
Gradle - the Enterprise Automation Tool
Izzet Mustafaiev
 
What's new in Gradle 4.0
Eric Wendelin
 
Serverless Container with Source2Image
QAware GmbH
 
Ad

Recently uploaded (20)

DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
Import Data Form Excel to Tally Services
Tally xperts
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Streamline Contractor Lifecycle- TECH EHS Solution
TECH EHS Solution
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Human Resources Information System (HRIS)
Amity University, Patna
 

Faster java ee builds with gradle [con4921]