Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Introduction - Gradle for Java Build

Prezi used for EXPERTALKS. This introduction is for beginners to get started on Gradle for their build automation scripts. Reference: gradle documentation and slideshares.
by

Tejaswita T

on 20 July 2015

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Introduction - Gradle for Java Build

Take away
Using Gradle for Java
References
Gradle - a solution that provides convention over configuration approach to the build process and an approach at building that isn't based on XML.
Ant
a flexible tool
xml scripts
build tasks
Why Gradle?
Gradle is?
a better way to build
Run tests
Release
Package
Deploy
Compile
Maven
build by convention
dependency management
But they are not enough :-(
sensible defaults yet easily customizable
readable and maintainable scripts
faster
easily scalable
A simple build cycle
Gradle setup
Hello world Gradle
More about Task
Build your Java project
Create your Jar
Manage dependency for Junit
Create and deploy your War
Multi-project build
http://gradle.org/documentation
http://gradle.org/docs/current/dsl/index.html
Building and Testing with Gradle
Gradle user guide
Setup instructions
Installation

Environment variables


Run gradle -v
Basic script
build.gradle

task hello << {
println 'Hello world!'
}
Forum
http://forums.gradle.org/gradle
Requires JAVA_HOME
Set GRADLE_HOME
Add $GRADLE_HOME/bin to PATH
Faster
Concise
Groovy DSL
Flexible
Programmable
Integrates with Ant
Supports Groovy and Scala
Scalable
Structured
Open source
Incremental builds make it faster
apply plugin : 'java'
build.gradle
Concise - Smaller scripts
allprojects {
task hello<< { task ->
println "I am in $task.project.name"
}
}

subprojects {
repositories {
mavenCentral()
}

project(':provider').hello << {
println "I am project specific task"
}
Groovy DSL
//Multiple source directories
sourceSets.main.java.srcDirs =['src/main/java','srcAdditional/main/java']
sourceSets.main.java.srcDirs 'srcAdditionalTwo/main/java'

//Multiple test source directories
sourceSets.test.java.srcDirs =['src/test/java','srcAdditional/test/java']
sourceSets.test.java.srcDirs 'srcAdditionalTwo/test/java'
Flexibility
build.gradle
ant.importBuild 'build.xml'


build.xml
<project>
<target name="hello">
<echo>Hello, from Ant</echo>
</target>
</project>
using ant with AntBuilder
task zip << {
ant.zip(destfile: 'archive.zip') {
fileset(dir: 'src') {
include(name: '**.xml')
exclude(name: '**.java')
}
}
}
Integration with Ant
build.xml
task createDatabase(type: MySqlTask) {
sql = 'CREATE DATABASE IF NOT EXISTS example'
}

task createUser(type: MySqlTask, dependsOn: createDatabase) {
sql = "GRANT ALL PRIVILEGES ON example.*
TO exampleuser@localhost IDENTIFIED BY 'passw0rd'"
}

task createTable(type: MySqlTask, dependsOn: createUser) {
username = 'exampleuser'
password = 'passw0rd'
database = 'example'
sql = 'CREATE TABLE IF NOT EXISTS users
(id BIGINT PRIMARY KEY, username VARCHAR(100))'
}
Programmable
class MySqlTask extends DefaultTask {

def hostname = 'localhost'
def port = 3306
def sql
def database
def username = 'root'
def password = 'password'

@TaskAction
def runQuery() {
def cmd
if(database) {
cmd = "mysql -u ${username} -p${password} -h ${hostname}
-P ${port} ${database} -e "
}
else {
cmd = "mysql -u ${username} -p${password} -h ${hostname} -P ${port} -e "
}
project.exec {
commandLine = cmd.split().toList() + sql
}
}
}
Get Started
Heads up
(cc) image by nuonsolarteam on Flickr
Source
An Introduction
Easy to customize default behavior
DSL is more readable than xml
Faster
Go ahead and write your own tasks
Find the examples on git hub:

https://github.com/tejaswita/gradle-introduction.git
Full transcript