Skip to content

Instantly share code, notes, and snippets.

@xconnecting
xconnecting / build.gradle
Created November 21, 2012 23:43
Gradle: Call command line process
ant.condition(property: "os", value: "windows") { os(family: "windows") }
ant.condition(property: "os", value: "unix" ) { os(family: "unix") }
task execCommandLine(type:Exec) {
switch(ant.properties.os){
case 'windows':
commandLine 'cmd', '/c', 'echo', 'hello'
break
case 'unix':
commandLine 'echo', 'hello'
@xconnecting
xconnecting / build.gradle
Created November 19, 2012 02:10
Gradle: Add group and description to task defined in custom plugin
class Greeting implements Plugin<Project> {
void apply(Project target) {
def helloTask = target.task('hello', type: HelloTask)
helloTask .group = 'greeting'
helloTask .description = 'Say hello.'
target.task('hi', type: HiTask){
group = 'greeting'
description = 'Say hi.'
}
}
@xconnecting
xconnecting / build.gradle
Created November 16, 2012 06:07
Gradle: Task group and description
task hello << {
println 'hello'
}
hello.group = 'greeting'
hello.description = 'Say hello.'
task hi << {
println 'hi'
}
hi.group = 'greeting'
@xconnecting
xconnecting / build.gradle
Created November 14, 2012 05:43
Gradle: Configure project property from other build script
// the contents of .gradle/other.gradle is:
// ext.prop1 = 'value1'
apply from: "${System.properties['user.home']}/.gradle/other.gradle"
task testProperties << {
println project.prop1
}
@xconnecting
xconnecting / build.gradle
Created November 13, 2012 07:37
Gradle: collect depenentjars into a directory in the project
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
dependencies { compile 'commons-lang:commons-lang:2.6' }
repositories {
mavenCentral()
}
@xconnecting
xconnecting / build.gradle
Created November 9, 2012 02:50
Gradle: Check current OS
ant.condition(property: "os", value: "windows") { os(family: "windows") }
ant.condition(property: "os", value: "unix" ) { os(family: "unix") }
task typeos << {
switch(ant.properties.os){
case 'windows':
println 'This is windows.'
break
case 'unix':
println 'This is unix.'
@xconnecting
xconnecting / build.gradle
Created November 8, 2012 06:30
Gradle: print buildscript dependencies
apply plugin: 'eclipse'
apply plugin: 'maven'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.apache.commons:commons-email:1.2'
}
@xconnecting
xconnecting / build.gradle
Created November 8, 2012 03:41
hasProperty method in Gradle Task
defaultTasks 'checkProperty'
task checkProperty << {
println hasProperty('test')
println project.hasProperty('test')
}
@xconnecting
xconnecting / build.gradle
Created November 8, 2012 01:46
Sample: use Gradle custom plugin
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'greeting'
buildscript {
repositories { mavenLocal() }
dependencies { classpath 'com.example:greet:1.0-SNAPSHOT' }
}
task hi(type:com.example.GreetingTask){
@xconnecting
xconnecting / build.gradle
Created November 8, 2012 00:56
Sample: build.gradle for Gradle custom plugin
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'maven'
group = 'com.example'
archivesBaseName = 'greet'
version = '1.0-SNAPSHOT'
dependencies {
compile gradleApi()