https://www.yiibai.com/gradle/
task hello{
doLast{
println 'hello workd!'
}
}
task upper << {
String expString = 'YiiBai gradle tutorials'
println "Original: " + expString
println "Upper case: " + expString.toUpperCase()
}
task count << {
4.times {
print "$it "
}
}
task groovyJDKMethod << {
String myName = "Yiibai";
myName.each() {
println "${it}"
};
}
task intro(dependsOn: hello) << {
println "I'm Gradle"
}
task taskX(dependsOn: 'taskY') << {
println 'taskX'
}
task taskY << {
println 'taskY'
}
task hello1 <<
{
println hello1.name
println project.hello1.name
}
task hello2 <<
{
println tasks.hello2.name
println tasks['hello2'].name
}
task task3 << {
println 'task3'
}
task task4 << {
println 'task4'
}
task3.dependsOn task4
//build.gradle 注释也可以用双斜杠
task taskX1 << {
println 'taskX'
}
taskX1.dependsOn {
tasks.findAll {
task -> task.name.startsWith('lib')
}
}
task lib1 << {
println 'lib1'
}
task lib2 << {
println 'lib2'
}
task notALib << {
println 'notALib'
}
//1.这个是怎么玩的?
task copy(type: Copy) {
description 'Copies the resource directory to the target directory.'
from 'resources'
into 'target'
include('**/*.txt', '**/*.xml', '**/*.properties')
println("description applied")
}
task compile << {
println 'We are doing the compile.'
}
compile.doFirst {
// Here you would put arbitrary conditions in real life.
// But this is used in an integration test so we want defined behavior.
if (true) { throw new StopExecutionException() }
}
task myTask(dependsOn: 'compile') << {
println 'I am not affected'
}
//声明依赖关系
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
repositories {
maven {
url "http://repo.mycompany.com/maven2"
}
}
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://localhost/tmp/myRepo/")
}
}
}