0
Gradle v.1.0
Andrii Khaisin
Provectus IT
27.07.2013
About me
Senior Software Developer
at Provectus IT
for Men's Wearhouse
Gradle in a few words
• Gradle is task oriented build tool.
• Gradle has a set of default plugins which
define conventions...
What we need from a build tool
• Ability to create and support build scripts
• Ability to define projects hierarchy for mu...
Lets some practice
• Projects structure
• Build running
• Groovy is everywhere
• Tasks
• Plugin usage
• Repositories
• Dep...
Projects structure
• Project object model
• Convention over configuration
• Customize project model with build.gradle
• Sp...
Projects structure example
project/
api/
src/
build.gradle
data/
src/
war/
src/
main/
test/
build.gradle
settings.gradle
Build running
Gradle Installing approaches
• Locally installed Gradle distribution
• Gradle Wrapper - Keep it with you pro...
Groovy is everywhere
• Gradle scripts are Groovy scripts
• Gradle works in JVM
• All Java world in your hands
Groovy is everywhere example
// Somewhere in build.gradle
def env = System.getenv();
System.getenv().each {
println it
}
d...
Tasks
• Task is a named piece of work
• Tasks have relations between each other
• Tasks creates steps by step process of
p...
Tasks example
def env;
def user;
task prepareEnv << {
env = System.getenv();
}
task prepareUser (dependsOn:
'prepareEnv') ...
Plugins usage
1. Declare that certain plugin will be used
apply plugin: 'java' – adds Java lifecircle
2. Configure propert...
Java plugin and its tasks
Java plugin define set of tasks and dependencies between
the. In the way there is create lifecir...
Repositories
repositories {
mavenLocal()
mavenCentral()
mavenRepo name: "lib", url:"libs"
mavenRepo url: "http://repo.comp...
Dependencies
• Dependency is described by group, name, version and
other optional attributes
• Dependency types are config...
Dependencies example
allprojects {
dependencies {
compile ''commons-collections:commons-collections:3.1''
testCompile grou...
Custom plugins and tasks
There are places where custom plugins could
be stored:
• build.gradle
• apply from: 'other.gradle...
Custom plugins - buildSrc
buildSrc/ - Additional module with build script sources
src/
main/
groovy/
Wsdl2JavaPlugin.groov...
Custom plugins - wsdl2java
def class Wsdl2JavaPlugin implements Plugin<Project> {
void apply(Project project) {
// Take co...
Gradle is
• powerful
• simple
• compact
• evolving
• possible to debug
Gradle is just fun!
That's all :)
Links
Build tools
• http://www.gradle.org/
• http://buildr.apache.org/
• http://rubyforge.org/projects/rake
• http://ant.a...
Upcoming SlideShare
Loading in...5
×

Gradle

1,609

Published on

Introduction to build automation tool Gradle.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,609
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
81
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Gradle"

  1. 1. Gradle v.1.0 Andrii Khaisin Provectus IT 27.07.2013
  2. 2. About me Senior Software Developer at Provectus IT for Men's Wearhouse
  3. 3. Gradle in a few words • Gradle is task oriented build tool. • Gradle has a set of default plugins which define conventions and standard life cycle of project build. • Gradle build scripts are Groovy scripts which customize default workflow for your needs. • Gradle works well for Java projects and for non Java projects as well.
  4. 4. What we need from a build tool • Ability to create and support build scripts • Ability to define projects hierarchy for multi module build • Ability to manage project dependencies • Ability to implement custom build logic • Ability to extend available plugins • Ability to develop new own plugins • Ability to support build configurations
  5. 5. Lets some practice • Projects structure • Build running • Groovy is everywhere • Tasks • Plugin usage • Repositories • Dependencies • Custom plugin
  6. 6. Projects structure • Project object model • Convention over configuration • Customize project model with build.gradle • Split big scripts into parts • Put submodule related script into separate file or keep everything in one file.
  7. 7. Projects structure example project/ api/ src/ build.gradle data/ src/ war/ src/ main/ test/ build.gradle settings.gradle
  8. 8. Build running Gradle Installing approaches • Locally installed Gradle distribution • Gradle Wrapper - Keep it with you project and wrapper solve all other tasks as Gradle version, downloading Gradle and etc. • GVM - Groovy enVironment Manager Gradle launch gradle <params> [task1, [task2, taks3, ...]]
  9. 9. Groovy is everywhere • Gradle scripts are Groovy scripts • Gradle works in JVM • All Java world in your hands
  10. 10. Groovy is everywhere example // Somewhere in build.gradle def env = System.getenv(); System.getenv().each { println it } def user = env['USER']; if (user != null) { println "User: $user"; }
  11. 11. Tasks • Task is a named piece of work • Tasks have relations between each other • Tasks creates steps by step process of project build
  12. 12. Tasks example def env; def user; task prepareEnv << { env = System.getenv(); } task prepareUser (dependsOn: 'prepareEnv') << { user = env['USER']; } task printEnv (dependsOn: 'prepareEnv') << { env.each { println it } } task printUser (dependsOn: 'prepareUser' ) << { if (user != null) { println "User: $user"; } }
  13. 13. Plugins usage 1. Declare that certain plugin will be used apply plugin: 'java' – adds Java lifecircle 2. Configure properties of this plugin 3. Launch task defined by this plugin
  14. 14. Java plugin and its tasks Java plugin define set of tasks and dependencies between the. In the way there is create lifecircle similar to lifecircle available in Maven
  15. 15. Repositories repositories { mavenLocal() mavenCentral() mavenRepo name: "lib", url:"libs" mavenRepo url: "http://repo.company.com/maven" ivy { url "http://repo.company.com/ivy" } // Any custom defined source of artifacts }
  16. 16. Dependencies • Dependency is described by group, name, version and other optional attributes • Dependency types are configurable by plugins • Java plugin adds compile, runtime, testCompile, testRuntime • Gradle support dependency version ranges • transitive dependency management
  17. 17. Dependencies example allprojects { dependencies { compile ''commons-collections:commons-collections:3.1'' testCompile group: 'junit', name: 'junit', version: '4.+' } } project(':api') { dependencies { compile ''javax.xml.ws:jaxws-api:$wsVersion'' } } project(':server') { dependencies { runtime ''com.sun.xml.ws:jaxws-rt:$wsVersion'' } }
  18. 18. Custom plugins and tasks There are places where custom plugins could be stored: • build.gradle • apply from: 'other.gradle' • buildSrc folder which is automatically used as a sources of additional scripts • Remotelocal repositories
  19. 19. Custom plugins - buildSrc buildSrc/ - Additional module with build script sources src/ main/ groovy/ Wsdl2JavaPlugin.groovy test/ build.gradle - more configuration if needed api/ data/ server/ build.gradle settings.gradle
  20. 20. Custom plugins - wsdl2java def class Wsdl2JavaPlugin implements Plugin<Project> { void apply(Project project) { // Take configuration of WSDL file path // Inject task in build life cycle project.tasks.processResources.dependsOn Wsdl2JavaTask // Generate sources and add theirs folder to Sources Set } } // Then somewhere in the project project(':api') { apply plugin: 'wsdl2java' wsdl2java src:"api/src/main/resources/wsdl/Service.wsdl" }
  21. 21. Gradle is • powerful • simple • compact • evolving • possible to debug Gradle is just fun!
  22. 22. That's all :)
  23. 23. Links Build tools • http://www.gradle.org/ • http://buildr.apache.org/ • http://rubyforge.org/projects/rake • http://ant.apache.org/ • http://maven.apache.org/ • http://www.gnu.org/software/make/ • http://www.cmake.org/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×