Skip to content

Instantly share code, notes, and snippets.

@xconnecting
xconnecting / ReadWrite.groovy
Created September 18, 2012 04:54
Groovy: file read and write
def reader = new File('in.txt').newReader('UTF-8')
def writer = new File('out.txt').newWriter('UTF-8')
reader.eachLine{
println it
writer.writeLine(it)
}
writer.close()
@xconnecting
xconnecting / build.gradle
Created October 17, 2012 07:55
Get password console during executing gradle task
task readPassword << {
// Get password from user input.
def console = System.console()
console.writer().write "\n"
def password = console.readPassword('%s: ', 'Please enter the password')
println password
}
@xconnecting
xconnecting / build.gradle
Created October 18, 2012 04:07
Gradle script for making directories for Groovy project
apply plugin: 'groovy'
apply plugin: 'eclipse'
task mkdirs << {
sourceSets.all {
it.groovy.srcDirs.each { it.mkdirs() }
it.resources.srcDirs.each { it.mkdirs() }
}
}
@xconnecting
xconnecting / build.gradle
Created October 25, 2012 01:20
dependencies and repositories in Gradle
apply plugin: 'java'
apply plugin: 'eclipse'
dependencies { compile 'commons-lang:commons-lang:2.6' }
repositories {
// Maven central repository
mavenCentral()
// local repository
@xconnecting
xconnecting / build.gradle
Created October 26, 2012 06:10
Use custom Ant task from Gradle
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
configurations { taskdef }
repositories { mavenCentral() }
dependencies { taskdef 'java2html:j2h:1.3.1' }
@xconnecting
xconnecting / build.gradle
Created October 31, 2012 06:03
Gradle: Change setting using P option
defaultTasks 'dbsetting'
def envList = ['dev', 'qa', 'prod']
if (!hasProperty('env')) {
ext.env = System.env['GRADLE_ENV'] ?: envList[0]
}
if(!envList.find{it == ext.env}){
throw new Exception("There is no environment named '$ext.env'")
@xconnecting
xconnecting / build.gradle
Created November 1, 2012 01:57
Gradle: Deploying to a Maven repository
apply plugin: 'java'
apply plugin: 'maven'
// If archivesBaseName is not specified, the project name is used for name
archivesBaseName = 'myapp'
group = 'com.mycompany.app'
version ='0.1'
uploadArchives {
repositories {
@xconnecting
xconnecting / build.gradle
Created November 6, 2012 01:05
Sample: Gradle custom task in build.gradle
task hello (type: GreetingTask){
}
task hi (type: GreetingTask){
greeting = 'Hi'
}
class GreetingTask extends DefaultTask {
def greeting = 'Hello'
@TaskAction
@xconnecting
xconnecting / build.gradle
Created November 7, 2012 00:27
Sample: Gradle custom plugin in build.gradle
class Greeting implements Plugin<Project> {
void apply(Project target) {
target.task('greet', type: GreetingTask)
}
}
class GreetingTask extends DefaultTask {
def greeting = 'Hello'
@TaskAction
def greet() {
@xconnecting
xconnecting / Greeting.groovy
Created November 8, 2012 00:53
Sample: Gradle plugin class
package com.example
import org.gradle.api.Plugin
import org.gradle.api.Project
class Greeting implements Plugin<Project> {
void apply(Project target) {
target.task('greet', type: GreetingTask)
}
}