Rocking the Gradle
Ken Sipe
Rocking The Gradle
Rocking the GradleAbout Speaker
Developer: Embedded, C++, Java, Groovy, Grails, C#, Objective C
Speaker: JavaOne 2009 Rock Star, NFJS, JAX
Microsoft MCP
Sun Certified Java 2 Architect
Master of Scrums
Agile Coach
Instructor: Visi...
Ken Sipe
Rocking The Gradle
Rocking the GradleAbout Speaker
Developer: Embedded, C++, Java, Groovy, Grails, C#, Objective C
Speaker: JavaOne 2009 Rock Star, NFJS, JAX
Microsoft MCP
Sun Certified Java 2 Architect
Master of Scrums
Agile Coach
Instructor: VisiBroker CORBA
Rational Rose, OOAD
http://kensipe.blogspot.com/
http://del.icio.us/kensipe
twitter: @kensipe
ken.sipe@gradleware.com
Rocking the GradleJava Build Tools
javac
IDE
ANT
Maven
ANT + Ivy
Gradle
Rocking the GradleGradle Book
Rocking the GradleWhat is Gradle?
nBuilt on top of Ant + Ivy
nBuild DSL written in Groovy
nUses Groovy AntBuilder
¨ant.compile, ant.jar
nPlugins define common tasks to build
different types of projects
¨java, groovy, war, …
Rocking the GradleWhat is Gradle?
Gradle is Declarative
Specify what...
...not how
Rocking the Gradle
Quick Demo
Rocking the GradleCreate a task
createTask('hello') { // depreciated
println 'Hello World'
}
task hello << {
println 'Hello world!'
}
task intro(dependsOn: hello) << {
println "I'm Gradle"
}
project.tasks.add('someTask').doFirst {
// do something
}
Rocking the GradleDSL Syntax And Tasks
task hello << { println 'Hello' }
// direct API access is fine for single statements
hello.dependsOn otherTask
// for multiple access we prefer closure syntax
hello {
onlyIf { day == 'monday' }
dependsOn otherTask
}
// combining Configuration and Actions
task hello {
onlyIf {
day == 'monday'
}
doFirst {println 'Hello'}
}
Rocking the GradleSample Simple Build File
apply plugin:'war'
version = 0.1
repositories {
mavenCentral()
}
dependencies {
compile "commons-lang:commons-lang:2.4"
}
Rocking the Gradle
Beyond the Basics
Rocking the Gradle
Does it really matter if your build
system uses XML or Groovy?
Can there be aspects of the
build that are difficult from a
declarative perspective?
Rocking the GradleNon Declarative Examples
version = "1.0-${new Date().format('yyyyMMdd')}"
task sources {
! sourceSets.test.allGroovy
! ! .matching {include '**/*Demo*.groovy' }
! ! .files.each {
! ! ! println “$it.absolutePath”
! }
}
Rocking the GradleExtensible Object Model
tasks.withType(Jar).allObjects { jarTask ->
! jarTask.osgi = new DefaultOsgiManifest()
! jarTask.doFirst { task ->
! ! importOsgiManifestIntoManifest(task) }
}
Rocking the GradleJump Between Phases
task release(dependsOn: assemble) << {
println 'We release now'
}
build.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(':release')) {
version = '1.0'
} else {
version = '1.0-SNAPSHOT'
}
}
Rocking the Gradle
What makes Gradle Rock!
Rocking the Gradle
#1 - Gradle Wrapper
Rocking the GradleGradle Wrapper
enables enterprise wide project conventions
Rocking the GradleGradle Wrapper
enables bootstrap
to a working build
Rocking the GradleContinuous Delivery Best Practice
Rocking the Gradle
#2 - Multi-Project Builds
Rocking the GradleMulti-Project
nDependencies
¨Source Level
nIncremental Builds
nLess Hoops!
Rocking the Gradle
#3 - Integration with ANT and Maven
Rocking the GradleIntegration with Maven
nIntegration with Maven repositories
¨autogeneration of pom.xml
¨install to local Maven repo
¨deploy to any remote Repo
¨full maven metadata generation
nIntegration of Maven builds in the future
Rocking the GradleIntegration with ANT
Hello, from Ant
build.xml
ant.importBuild 'build.xml'
hello.doFirst { println 'Here comes Ant' }
task intro << { println 'Hello, from Gradle'}
build.gradle
~/projects/playground/gradle/ant$ gradle hello
:intro
Hello, from Gradle
:hello
Here comes Ant
[ant:echo] Hello, from Ant
output:
Rocking the GradleRunning Processes from Gradle
ant.java(classname: 'com.my.classname', fork: true,
classpath: "${sourceSets.main.runtimeClasspath.asPath}")
Rocking the GradleCobertura (1/2)
apply plugin:'java'
def cobSerFile="${project.buildDir}/cobertura.ser"
def srcOriginal="${sourceSets.main.classesDir}"
def srcCopy="${srcOriginal}-copy"
repositories {
mavenCentral()
}
dependencies {
testRuntime 'net.sourceforge.cobertura:cobertura:1.9.3'
testCompile 'junit:junit:4.5'
}
test.doFirst {
ant {
delete(file:cobSerFile, failonerror:false)
delete(dir: srcCopy, failonerror:false)
taskdef(resource:'tasks.properties', classpath: configurations.testRuntime.asPath)
copy(todir: srcCopy) {
fileset(dir: srcOriginal)
}
'cobertura-instrument'(datafile:cobSerFile) {
fileset(dir: srcOriginal,
includes:"my/classes/**/*.class",
excludes:"**/*Test.class")
}
}
}
Rocking the GradleCobertura (2/2)
test {
// pass information on cobertura datafile to your testing framework
// see information below this code snippet
}
test.doLast {
if (new File(srcCopy).exists()) {
// replace instrumented classes with backup copy again
ant {
delete(file: srcOriginal)
move(file: srcCopy,
tofile: srcOriginal)
}
// create cobertura reports
ant.'cobertura-report'(destdir:"${project.buildDirName}/test-results",
format:'html', srcdir:"src/main/java", datafile:cobSerFile)
}
}
Rocking the Gradle
#4 - Incremental Builds
Rocking the Gradle
#5 - Boot Strapping Build Scripts
GradleApplying
n Any gradle script can be a plugin.
n Binary plugins must be in the build script classpath
¨can have id's (meta properties in the jar).
¨will learn later how to add elements to the build script
classpath.
¨The build-in plugins are by default in the build script classpath.
apply from: 'otherScript.gradle'
apply from: 'http://mycomp.com/otherScript.gradle'
apply plugin: org.gradle.api.plugins.JavaPlugin
apply plugin: 'java'
Rocking the GradleJar
n Jars can be added to the buildscript classpath
¨Custom build logic
¨Plugins
¨Helper classes (e.g. commons-math)
buildscript {
repositories { mavenCentral() }
dependencies {
classpath "commons-lang:commons-lang:3.1"
classpath files('lib/foo.jar')
}
}
Rocking the Gradle
#6 - Corporate Defined Conventions
Rocking the GradleProject Standards
Rocking the Gradle
#7 - Rich Model
with Implicit Depends
Rocking the GradleImplicit Depends
Rocking the Gradle
#8 - Concise
Express what is different...
...Not all the details of how
your build is the same
Rocking the Gradle
#9 - Gradle is Groovy
Rocking the Gradle
Gradle Rocks!
Rocking the Gradle
n Get More Info:
¨http://forums.gradle.org
¨http://gradleware.com
¨Road Map
n http://www.gradle.org/roadmap
Summary
Rocking the Gradle
n Closing and Q&A
¨Please fill out the session evaluation
¨Ken Sipe
n ken.sipe@gmail.com
n kensipe.blogspot.com
n twitter: @kensipe
Summary
本文档为【Rocking the Gradle】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。