/
build.gradle
99 lines (84 loc) · 3.07 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import org.example.*
// tag::failed-inferred-task-dep[]
plugins {
// end::failed-inferred-task-dep[]
id 'base'
// tag::failed-inferred-task-dep[]
id 'java-library'
}
// end::failed-inferred-task-dep[]
repositories {
mavenCentral()
}
dependencies {
implementation group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
testImplementation group: 'junit', name: 'junit', version: '4.+'
}
// tag::custom-task-class[]
tasks.register('processTemplates', ProcessTemplates) {
templateEngine = TemplateEngineType.FREEMARKER
templateData.name = 'test'
templateData.variables = [year: '2012']
outputDir = file(layout.buildDirectory.dir('genOutput'))
sources fileTree('src/templates')
}
// end::custom-task-class[]
// tag::task-arg-method[]
def copyTemplates = tasks.register('copyTemplates', Copy) {
into file(layout.buildDirectory.dir('tmp'))
from 'src/templates'
}
tasks.register('processTemplates2', ProcessTemplates) {
// ...
// end::task-arg-method[]
templateEngine = TemplateEngineType.FREEMARKER
templateData.name = 'test'
templateData.variables = [year: '2012']
outputDir = file(layout.buildDirectory.dir('genOutput'))
// tag::task-arg-method[]
sources copyTemplates
}
// end::task-arg-method[]
// tag::failed-inferred-task-dep[]
tasks.register('badInstrumentClasses', Instrument) {
classFiles.from fileTree(tasks.named('compileJava').flatMap { it.destinationDirectory }) {}
destinationDir = file(layout.buildDirectory.dir('instrumented'))
}
// end::failed-inferred-task-dep[]
// tag::inferred-task-dep[]
tasks.register('instrumentClasses', Instrument) {
classFiles.from tasks.named('compileJava').map { it.outputs.files }
destinationDir = file(layout.buildDirectory.dir('instrumented'))
}
// end::inferred-task-dep[]
// tag::inferred-task-dep-with-files[]
tasks.register('instrumentClasses2', Instrument) {
classFiles.from layout.files(tasks.named('compileJava'))
destinationDir = file(layout.buildDirectory.dir('instrumented'))
}
// end::inferred-task-dep-with-files[]
// tag::inferred-task-dep-with-builtby[]
tasks.register('instrumentClassesBuiltBy', Instrument) {
classFiles.from fileTree(tasks.named('compileJava').flatMap { it.destinationDirectory }) {
builtBy tasks.named('compileJava')
}
destinationDir = file(layout.buildDirectory.dir('instrumented'))
}
// end::inferred-task-dep-with-builtby[]
// tag::disable-up-to-date-checks[]
tasks.register('alwaysInstrumentClasses', Instrument) {
classFiles.from layout.files(tasks.named('compileJava'))
destinationDir = file(layout.buildDirectory.dir('instrumented'))
doNotTrackState("Instrumentation needs to re-run every time")
}
// end::disable-up-to-date-checks[]
// tag::git-clone[]
tasks.register("cloneGradleProfiler", GitClone) {
destinationDir = layout.buildDirectory.dir("gradle-profiler") // <3>
remoteUri = "https://github.com/gradle/gradle-profiler.git"
commitId = "d6c18a21ca6c45fd8a9db321de4478948bdf801b"
}
// end::git-clone[]
tasks.named('build') {
dependsOn 'processTemplates', 'processTemplates2'
}