on Thursday, 10 October 2013
I wanted to use the Gradle Wrapper, but wanted to keep the download internal to avoid having to expose proxy setting in the gradlew scripts.

The change was quite simple. We hosted the files on a staging server (Windows) and simply changed the gradle-wrapper.properties to the following:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=file:////SERVER/some/path/gradle/distributions/gradle-1.7-bin.zip

on Wednesday, 2 October 2013
I've been working quite closely with one of the testers who's written a test suite using Selenium. He had initially wrote a single gradle task for each browser.

As i hope you can see its a little clunky:


task intTestFirefox(type: Test) {
maxParallelForks = 2
systemProperties['LOCAL_DRIVER'] = false
systemProperties['REMOTE_DRIVER'] = true
systemProperties['SAUCE_DRIVER'] = false
systemProperties['GRID_HOST'] = 'localhost'
systemProperties['GRID_PORT'] = '4444'
systemProperties['BROWSER'] = 'firefox'
systemProperties['PLATFORM'] = 'WINDOWS'
systemProperties['BASE_TEST_RESULTS_PATH'] = "$buildDir/Screenshots/$version"
systemProperties['APPLICATION_URL'] = 'http://someurl'
testClassesDir = sourceSets.inttest.output.classesDir
classpath = sourceSets.inttest.runtimeClasspath
useTestNG()
}
task intTestChrome(type: Test) {
maxParallelForks = 2
systemProperties['LOCAL_DRIVER'] = false
systemProperties['REMOTE_DRIVER'] = true
systemProperties['SAUCE_DRIVER'] = false
systemProperties['GRID_HOST'] = 'localhost'
systemProperties['GRID_PORT'] = '4444'
systemProperties['BROWSER'] = 'chrome'
systemProperties['webdriver.chrome.driver'] = 'C:/Automation/lib/chromedriver.exe'
systemProperties['PLATFORM'] = 'WINDOWS'
systemProperties['BASE_TEST_RESULTS_PATH'] = "$buildDir/Screenshots/$version"
systemProperties['APPLICATION_URL'] = 'http://someurl'
testClassesDir = sourceSets.inttest.output.classesDir
classpath = sourceSets.inttest.runtimeClasspath
useTestNG()
}
So, I set out to make this more flexible and minimize the amount of code in the build file. Using rules which are provided by the Gradle API I was able to write the following task:


tasks.addRule('Rule Usage: intTest<Browser>') { String taskName ->
if(taskName.startsWith('intTest')) {
task(taskName, type: Test) {
ext.browser = taskName - 'intTest'
systemProperties['LOCAL_DRIVER'] = false
systemProperties['REMOTE_DRIVER'] = true
systemProperties['SAUCE_DRIVER'] = false
systemProperties['BROWSER'] = ext.browser
systemProperties['GRID_HOST'] = 'localhost'
systemProperties['GRID_PORT'] = '4444'
systemProperties['PLATFORM'] = 'WINDOWS'
systemProperties['BASE_TEST_RESULTS_PATH'] = "$buildDir/Screenshots/$version"
systemProperties['APPLICATION_URL'] = 'http://someurl'
maxParallelForks = 2
testClassesDir = sourceSets.inttest.output.classesDir
classpath = sourceSets.inttest.runtimeClasspath
useTestNG()
}
}
}
Now all thats required is "gradle intTestChrome" or "gradle intTestFirefox".... perfect!
on Tuesday, 1 October 2013

This simple Gist adds 2 additional output listeners; Standard Out and Standard Error and pipes their output to a build log.

def tstamp = new Date().format('yyyy-MM-dd_HH-mm-ss')
def buildLogDir = "${rootDir}/build/logs"
mkdir("${buildLogDir}")
def buildLog = new File("${buildLogDir}/${tstamp}_buildLog.log")
import org.gradle.logging.internal.*
System.setProperty('org.gradle.color.error', 'RED')
gradle.services.get(LoggingOutputInternal).addStandardOutputListener (new StandardOutputListener () {
void onOutput(CharSequence output) {
buildLog << output
}
})
gradle.services.get(LoggingOutputInternal).addStandardErrorListener (new StandardOutputListener () {
void onOutput(CharSequence output) {
buildLog << output
}
})
view raw logging.gradle hosted with ❤ by GitHub