Created
October 24, 2014 07:58
-
-
Save ksomemo/1800ec0bd7efaf6a19e4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// doLastだけ or << だけでもよい | |
task hello << { | |
println 'Hello short syntax!' | |
} | |
hello.doFirst { | |
println 'Hello Venus' | |
} | |
hello.doLast { | |
println 'Hello Mars' | |
} | |
// 複雑のタスク | |
task upper << { | |
String someString = 'mY_nAmE' | |
println "Original: " + someString | |
println "Upper case: " + someString.toUpperCase() | |
} | |
// 繰り返し | |
task count << { | |
4.times { print "$it " } | |
} | |
// 依存関係 | |
task intro(dependsOn: hello) << { | |
println "I'm Gradle" | |
} | |
// ''つきの場合、未評価のタスクを遅延評価 | |
task taskX(dependsOn: 'taskY') << { | |
println 'taskX' | |
} | |
task taskY << { | |
println 'taskY' | |
} | |
// 動的にタスク定義 | |
4.times { counter -> | |
task "task$counter" << { | |
println "I'm task number $counter" | |
} | |
} | |
task0.dependsOn task2, task3 | |
// タスク内でのプロパティ定義と利用 | |
task myTask { | |
ext.myProperty = "myValue" | |
} | |
task printTaskProperties << { | |
println myTask.myProperty | |
} | |
// ファイル読み込みとant利用 | |
task loadfile << { | |
def files = file('../antLoadfileResources').listFiles().sort() | |
files.each { File file -> | |
if (file.isFile()) { | |
ant.loadfile(srcFile: file, property: file.name) | |
println " *** $file.name ***" | |
println "${ant.properties[file.name]}" | |
} | |
} | |
} | |
// 関数定義と利用 | |
task checksum << { | |
fileList('../antLoadfileResources').each {File file -> | |
ant.checksum(file: file, property: "cs_$file.name") | |
println "$file.name Checksum: ${ant.properties["cs_$file.name"]}" | |
} | |
} | |
File[] fileList(String dir) { | |
file(dir).listFiles({file -> file.isFile() } as FileFilter).sort() | |
} | |
// デフォルトタスク | |
defaultTasks 'clean', 'run' | |
task clean << { | |
println 'Default Cleaning!' | |
} | |
task run << { | |
println 'Default Running!' | |
} | |
task other << { | |
println "I'm not a default task!" | |
} | |
task distribution << { | |
println "We build the zip with version=$version" | |
} | |
task release(dependsOn: 'distribution') << { | |
println 'We release now' | |
} | |
gradle.taskGraph.whenReady {taskGraph -> | |
if (taskGraph.hasTask(release)) { | |
version = '1.0' | |
} else { | |
version = '1.0-SNAPSHOT' | |
} | |
} |
This file contains hidden or 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
#!/bin/sh | |
# prepare | |
GRADLE_DIR="gradle-2.1" | |
if [ ! -d $GRADLE_DIR ]; then | |
curl -L -O https://services.gradle.org/distributions/gradle-2.1-bin.zip | |
unzip gradle-2.1-bin.zip | |
fi | |
if [ -f "build.gradle" ]; then | |
cp build.gradle "$GRADLE_DIR/bin" | |
else | |
exit 1 | |
fi | |
cd $GRADLE_DIR | |
export GRADLE_HOME=$(pwd) | |
cd bin | |
# ant script file | |
if [ ! -d ../antLoadfileResources ]; then | |
mkdir ../antLoadfileResources | |
echo ' | |
<project default="create_run_jar" name="Create Runnable Jar for Project StringSimilarDetail"> | |
<!--this file was created by Eclipse Runnable JAR Export Wizard--> | |
<!--ANT 1.7 is required --> | |
<property name="bin.dir" value="bin" /> | |
<property name="classes.dir" value="classes" /> | |
<property name="lucene-gosen.jar" value="lucene-gosen-2.1-dev-naist-chasen.jar" /> | |
<property name="output.jar" value="output.jar" /> | |
<dirname property="project.path" file="${ant.file}" /> | |
<target name="create_run_jar"> | |
<unzip src="${project.path}/${lucene-gosen.jar}" dest="${project.path}/${lucene-gosen.jar}-unzip"/> | |
<copy todir="${project.path}/${classes.dir}/net/" overwrite="yes"> | |
<fileset dir="${project.path}/${lucene-gosen.jar}-unzip/net/" /> | |
</copy> | |
<copy todir="${project.path}/${classes.dir}/org/" overwrite="yes"> | |
<fileset dir="${project.path}/${lucene-gosen.jar}-unzip/org/" /> | |
</copy> | |
<jar destfile="${project.path}/${output.jar}" filesetmanifest="mergewithoutmain"> | |
<manifest> | |
<attribute name="Class-Path" value=". "/> | |
</manifest> | |
<fileset dir="${project.path}/${bin.dir}"/> | |
<fileset dir="${project.path}/${classes.dir}"/> | |
</jar> | |
</target> | |
</project> | |
' > ../antLoadfileResources/build.xml | |
fi | |
# execute tasks | |
tasks=( | |
hello | |
upper | |
upper | |
intro | |
taskX | |
task1 | |
task0 | |
printTaskProperties | |
loadfile | |
checksum | |
"" # default | |
distribution | |
release | |
) | |
for task in ${tasks[@]} | |
do | |
echo "" | |
echo "---------------------" | |
echo "task name is [$task]" | |
echo "" | |
gradle -q $task | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment