This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
println 'This is executed during the configuration phase.' | |
task configurated { | |
println 'This is also executed during the configuration phase.' | |
} | |
task test << { | |
println 'This is executed during the execution phase.' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Declaring the inputs and outputs of a task | |
//build.gradle | |
task transform { | |
ext.srcFile = file('mountains.xml') | |
ext.destDir = new File(buildDir, 'generated') | |
inputs.file srcFile | |
outputs.dir destDir | |
doLast { | |
println "Transforming source file." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1. Use the zipTree directly in the jar task rather than creating an intermediate zip. | |
//2. Use eachFile to change the relative path of each file to strip off the first folder. | |
jar { | |
from zipTree('runtime.jar') { | |
include 'classes/**/*.class' | |
eachFile { it.relativePath = it.relativePath.segments[1..-1] } | |
} | |
} | |
//Jar tasks have all of the CopySpec methods, which provide the eachFile abilities. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//configure the snapshot and the release repository in the 'Upload' task (e.g. the 'uploadArchives') task: | |
uploadArchives { | |
repositories { | |
mavenDeployer { | |
repository(url: 'http://myCompanyRepo.com:8081/releases') { | |
authentication(userName: 'admin', password: 'password'); | |
} | |
snapshotRepository(url: 'http://myCompanyRepo.com:8081/snapshots') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//get the latest version like | |
compile "junit:junit:+" | |
//or better specify at least the major version like | |
compile "junit:junit:4.+" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* The plugins used for this build. | |
*/ | |
/* | |
* Provides the compile, test, jar, etc tasks | |
*/ | |
apply plugin: 'java' | |
/* | |
* Generates the Eclipse project files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
configurations { | |
apt | |
} | |
dependencies { | |
compile 'com.squareup.dagger:dagger:1.1.0' | |
apt 'com.squareup.dagger:dagger-compiler:1.1.0' | |
} | |
android.applicationVariants.all { variant -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Gets the version name from the latest Git tag | |
*/ | |
def getVersionName = { -> | |
def stdout = new ByteArrayOutputStream() | |
exec { | |
commandLine 'git', 'describe', '--tags' | |
standardOutput = stdout | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A copy task mapping source directory structure onto a new destination structure | |
task complexCopy(type: Copy) { | |
from('src/main/templates') { | |
include '**/*.gtpl' | |
into 'templates' | |
} | |
from('i18n') | |
from('config') { | |
exclude 'Development*.groovy' | |
into 'config' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Renaming files using regular expressions | |
task rename(type: Copy) { | |
from 'source' | |
into 'dest' | |
rename(/file-template-(\d+)/, 'production-file-$1.txt') | |
} | |
//Renaming files programmatically | |
task rename(type: Copy) { | |
from 'source' | |
into 'dest' |