File tree Expand file tree Collapse file tree
buildSrc/src/main/groovy/com/baeldung Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,3 +33,60 @@ task execSecondTest {
3333 }
3434 println ' This will be executed during the configuration phase as well.'
3535}
36+
37+ task welcome {
38+ doLast {
39+ println ' Welcome on the Baeldung!'
40+ }
41+ }
42+
43+ task welcomeWithGroup {
44+ group ' Sample category'
45+ doLast {
46+ println ' Welcome on the Baeldung!'
47+ }
48+ }
49+
50+ task welcomeWithGroupAndDescription {
51+ group ' Sample category'
52+ description ' Tasks which shows welcome message'
53+ doLast {
54+ println ' Welcome on the Baeldung!'
55+ }
56+ }
57+
58+ class PrintToolVersionTask extends DefaultTask {
59+ String tool
60+
61+ @TaskAction
62+ void printToolVersion () {
63+ switch (tool) {
64+ case ' java' :
65+ println System . getProperty(" java.version" )
66+ break
67+ case ' groovy' :
68+ println GroovySystem . version
69+ break
70+ default :
71+ throw new IllegalArgumentException (" Unknown tool" )
72+ }
73+ }
74+ }
75+
76+ task printJavaVersion (type : PrintToolVersionTask ) {
77+ tool ' java'
78+ }
79+
80+ task printGroovyVersion (type : PrintToolVersionTask ) {
81+ tool ' groovy'
82+ }
83+
84+ import com.baeldung.PrintToolVersionBuildSrcTask
85+
86+ task printJavaVersionBuildSrc (type : PrintToolVersionBuildSrcTask ) {
87+ tool ' java'
88+ }
89+
90+ task printGroovyVersionBuildSrc (type : PrintToolVersionBuildSrcTask ) {
91+ tool ' groovy'
92+ }
Original file line number Diff line number Diff line change 1+ package com.baeldung
2+
3+ import org.gradle.api.DefaultTask
4+ import org.gradle.api.tasks.TaskAction
5+
6+ class PrintToolVersionBuildSrcTask extends DefaultTask {
7+ String tool
8+
9+ @TaskAction
10+ void printToolVersion () {
11+ switch (tool) {
12+ case ' java' :
13+ println System . getProperty(" java.version" )
14+ break
15+ case ' groovy' :
16+ println GroovySystem . version
17+ break
18+ default :
19+ throw new IllegalArgumentException (" Unknown tool" )
20+ }
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments