Skip to content

Instantly share code, notes, and snippets.

@xconnecting
xconnecting / build.gradle
Created February 8, 2013 07:22
[Gradle] Execute Gradle Application or Script
apply plugin: 'groovy'
apply plugin: 'eclipse'
dependencies {
groovy localGroovy()
}
task execGroovy (type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = "example.Script"
@xconnecting
xconnecting / build.gradle
Created February 8, 2013 06:56
[Gradle] Execute Java Application
apply plugin: 'java'
apply plugin: 'eclipse'
task execJava (type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = "example.Main"
}
@xconnecting
xconnecting / build.gradle
Last active December 12, 2015 07:29
[Gradle] Java Compile Encoding
apply plugin: 'java'
apply plugin: 'eclipse'
compileJava.options.encoding = 'UTF-8'
@xconnecting
xconnecting / build.gradle
Created January 24, 2013 00:29
Gradle: Get standard output text
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 December 6, 2012 05:11
Gradle: Task Rules Sample
tasks.addRule("Pattern: sample<ID>") { String taskName ->
if (taskName.startsWith("sample")) {
task(taskName) << {
println taskName - 'sample'
}
}
}
@xconnecting
xconnecting / build.gradle
Created November 29, 2012 01:25
Gradle: Using jdbc in build script
import groovy.sql.Sql
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'maven'
repositories { mavenCentral() }
configurations { driver }
dependencies { driver 'org.xerial:sqlite-jdbc:3.7.2' }
@xconnecting
xconnecting / build.gradle
Created November 29, 2012 00:37
Gradle: Define dependency in custom plugin
class Greeting implements Plugin<Project> {
void apply(Project project) {
project.task('first', type: FirstTask)
project.task('second', type: SecondTask)
.dependsOn('first')
}
}
class FirstTask extends DefaultTask {
@TaskAction
@xconnecting
xconnecting / build.gradle
Created November 28, 2012 01:16
Gradle: git init through command line
ant.condition(property: "os", value: "windows") { os(family: "windows") }
ant.condition(property: "os", value: "unix" ) { os(family: "unix") }
task gitInit(type:Exec){
group = 'Git'
description = 'git init'
workingDir '.'
switch(ant.properties.os){
case 'windows':
commandLine 'cmd', '/c', 'git', 'init'
@xconnecting
xconnecting / build.gradle
Created November 27, 2012 01:41
Gradle: git init using JGit ant task
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
configurations { jgit }
repositories {
mavenRepo url: 'http://download.eclipse.org/jgit/maven'
mavenCentral()
}
@xconnecting
xconnecting / build.gradle
Last active October 13, 2015 05:27
Gradle: Can't copy to project directory
// This task raises IOException
task copyToProjectDir(type: Copy) {
from 'test1/test1.txt'
into '.'
}
// Workaround using ant property
task copyToProjectDir1 << {
ant.copy(file: 'test1/test1.txt', todir: '.')
}