java-tutorials/gradle/gradletaskdemo/build.gradle

111 lines
2.1 KiB
Groovy
Raw Normal View History

buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.shipkit:shipkit:0.9.117"
}
}
plugins {
id 'java'
}
apply from: 'aplugin.gradle'
apply plugin: 'org.shipkit.bintray-release'
//hello task
task hello {
doLast {
println 'Baeldung'
}
}
//Groovy in gradle task
task toLower {
doLast {
String someString = 'HELLO FROM BAELDUNG'
println "Original: " + someString
println "Lower case: " + someString.toLowerCase()
}
}
// Task dependencies
task helloGradle {
doLast {
println 'Hello Gradle!'
}
}
task fromBaeldung(dependsOn: helloGradle) {
doLast {
println "I'm from Baeldung"
}
}
//Adding behavior to a task via api
task helloBaeldung {
doLast {
println 'I will be executed second'
}
}
helloBaeldung.doFirst {
println 'I will be executed first'
}
helloBaeldung.doLast {
println 'I will be executed third'
}
helloBaeldung {
doLast {
println 'I will be executed fourth'
}
}
//Adding extra task properties
task ourTask {
ext.theProperty = "theValue"
}
task printTaskProperty {
doLast {
println ourTask.theProperty
}
}
//Declaring dependencies
dependencies {
compile group:
'org.springframework', name: 'spring-core', version: '4.3.5.RELEASE'
compile 'org.springframework:spring-core:4.3.5.RELEASE',
'org.springframework:spring-aop:4.3.5.RELEASE'
compile(
[group: 'org.springframework', name: 'spring-core', version: '4.3.5.RELEASE'],
[group: 'org.springframework', name: 'spring-aop', version: '4.3.5.RELEASE']
)
testCompile('org.hibernate:hibernate-core:5.2.12.Final') {
transitive = true
}
runtime(group: 'org.hibernate', name: 'hibernate-core', version: '5.2.12.Final') {
transitive = false
}
runtime "org.codehaus.groovy:groovy-all:2.4.11@jar"
runtime group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.11', ext: 'jar'
compile fileTree(dir: 'libs', include: '*.jar')
}