This repository has been archived by the owner on Sep 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.gradle.kts
257 lines (221 loc) · 9.47 KB
/
build.gradle.kts
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import org.jetbrains.dokka.gradle.DokkaTask
import java.net.URL
plugins {
base
id("org.jetbrains.dokka")
id("org.ajoberstar.github-pages")
}
buildscript {
// dokka requires a repository from which to download dokka-fatjar on demand
configure(listOf(repositories, project.repositories)) {
jcenter()
maven { url = uri("https://dl.bintray.com/kotlin/kotlin-dev") }
}
}
// Sources sources
// Uses local clones if available
val gradleGitUseLocalClone = file("../gradle/.git").isDirectory
val gradleGitUri =
if (gradleGitUseLocalClone) file("../gradle").toURI().toString()
else "https://github.com/gradle/gradle.git"
val gradleGitRef = "kotlin-dsl-docs"
val kotlinDslGitUseLocalClone = file("../kotlin-dsl/.git").isDirectory
val kotlinDslGitUri =
if (kotlinDslGitUseLocalClone) file("../kotlin-dsl").toURI().toString()
else "https://github.com/gradle/kotlin-dsl.git"
val kotlinDslGitRef = "v0.18.4"
logger.lifecycle("Gradle sources for Kotlin DSL API\n uri = $gradleGitUri\n ref = $gradleGitRef\n")
logger.lifecycle("Kotlin DSL sources for Kotlin DSL API\n uri = $kotlinDslGitUri\n ref = $kotlinDslGitRef\n")
// Groovy and Kotlin versions
// Required to be fetched at configuration time
val groovyVersionSourceFilePath = "gradle/dependencies.gradle"
val groovyVersion =
if (gradleGitUseLocalClone)
file("../gradle/$groovyVersionSourceFilePath").readLines().extractGroovyVersion()
else
URL("https://raw.githubusercontent.com/gradle/gradle/$gradleGitRef/$groovyVersionSourceFilePath")
.openStream().bufferedReader().use { it.lineSequence().toList().extractGroovyVersion() }
val kotlinVersionSourceFilePath = "kotlin-version.txt"
val kotlinVersion =
if (kotlinDslGitUseLocalClone)
file("../kotlin-dsl/$kotlinVersionSourceFilePath").readLines().extractKotlinVersion()
else
URL("https://raw.githubusercontent.com/gradle/kotlin-dsl/$kotlinDslGitRef/$kotlinVersionSourceFilePath")
.openStream().bufferedReader().use { it.lineSequence().toList().extractKotlinVersion() }
fun List<String>.extractGroovyVersion() =
find { it.startsWith("libraries.groovy =") }!!
.split("=").last().substringAfterLast("version: '").substringBeforeLast("'").trim()
fun List<String>.extractKotlinVersion() =
first().trim()
logger.lifecycle("Runtime versions for Kotlin DSL API\n Groovy $groovyVersion\n Kotlin $kotlinVersion\n")
val dokkaDependencies by configurations.creating
dependencies {
dokkaDependencies("org.codehaus.groovy:groovy-all:$groovyVersion")
dokkaDependencies("org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlinVersion")
dokkaDependencies("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
dokkaDependencies("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion")
}
tasks {
val cloningGroup = "cloning"
val apiSourcesGroup = "API sources"
// Gradle API sources extraction
val cloneGradle by creating(git.GitClone::class) {
group = cloningGroup
description = "Clones Gradle sources."
uri = gradleGitUri
ref = gradleGitRef
cloneDir = file("$buildDir/clones/gradle")
}
val gradleApiSources by creating(api.GradleApiSources::class) {
group = apiSourcesGroup
description = "Generates Gradle API sources."
gradleClone = cloneGradle.cloneDir
sourceDir = file("$buildDir/api-sources/gradle")
dependsOn(cloneGradle)
}
// Gradle Kotlin DSL API sources extraction and generation
val cloneKotlinDsl by tasks.creating(git.GitClone::class) {
group = cloningGroup
description = "Clones Gradle Kotlin DSL sources."
uri = kotlinDslGitUri
ref = kotlinDslGitRef
cloneDir = file("$buildDir/clones/kotlin-dsl")
}
val generateKotlinDslExtensions by creating(GradleBuild::class) {
dir = cloneKotlinDsl.cloneDir
tasks = listOf(":provider:generateExtensions")
dependsOn(cloneKotlinDsl)
}
val gradleKotlinDslApiSources by creating(api.GradleKotlinDslApiSources::class) {
group = apiSourcesGroup
description = "Generates Gradle Kotlin DSL API sources."
kotlinDslClone = cloneKotlinDsl.cloneDir
sourceDir = file("$buildDir/api-sources/gradle-kotlin-dsl")
dependsOn(generateKotlinDslExtensions)
}
// Gradle built-in plugins accessors API generation
val installGradle by creating(api.GradleInstall::class) {
gradleClone = cloneGradle.cloneDir
gradleInstall = file("$buildDir/install/gradle")
dependsOn(cloneGradle)
}
val buildWithCorePluginsDir = file("build-with-core-plugins")
val gradlePluginsAccessors by creating(api.GradlePluginsAccessors::class) {
gradleInstall = installGradle.gradleInstall
buildDirectory = buildWithCorePluginsDir
accessorsDir = file("$buildDir/generated/gradle-plugins-accessors")
dependsOn(installGradle)
}
// API docs generation using dokka
val dokka by getting(DokkaTask::class) {
dependsOn(gradleApiSources, gradleKotlinDslApiSources, gradlePluginsAccessors)
group = ""
moduleName = "api"
outputDirectory = "$buildDir/docs/dokka"
jdkVersion = 8
classpath = dokkaDependencies
sourceDirs = listOf(
gradleKotlinDslApiSources.sourceDir,
gradleApiSources.sourceDir,
gradlePluginsAccessors.accessorsDir)
includes = listOf("src/dokka/kotlin-dsl.md")
doFirst {
file(outputDirectory).deleteRecursively()
}
}
val apiDocumentation by creating {
group = "documentation"
description = "Generates Gradle Kotlin DSL API documentation."
dependsOn(dokka)
}
// Checks
val checkApiDocumentation by creating {
dependsOn(dokka)
group = "verification"
description = "Runs checks on the generated API documentation."
val apiDocsRoot = file(dokka.outputDirectory)
inputs.dir(apiDocsRoot)
doLast {
var gradleApiFound = false
var gradleKotlinDslApiFound = false
var gradleKotlinDslGeneratedApiFound = false
var gradlePluginsBlockAccessorsFound = false
var gradlePluginsAccessorsFound = false
val filesWithErrorClass = mutableListOf<File>()
apiDocsRoot.walk().filter { it.isFile }.forEach { file ->
val text = file.readText()
if (text.contains("ERROR CLASS")) {
filesWithErrorClass += file
}
if (!gradleApiFound && text.contains("id=\"org.gradle.api.Project\$task")) {
gradleApiFound = true
}
if (!gradleKotlinDslApiFound && text.contains("id=\"org.gradle.kotlin.dsl.KotlinBuildScript")) {
gradleKotlinDslApiFound = true
}
if (!gradleKotlinDslGeneratedApiFound && text.contains("embeddedKotlinVersion")) {
gradleKotlinDslGeneratedApiFound = true
}
if (!gradlePluginsBlockAccessorsFound && text.contains("name=\"org.gradle.kotlin.dsl\$base#org.gradle.plugin.use.PluginDependenciesSpec\"")) {
gradlePluginsBlockAccessorsFound = true
}
if (!gradlePluginsAccessorsFound && text.contains("name=\"org.gradle.kotlin.dsl\$checkstyle#org.gradle.api.Project")) {
gradlePluginsAccessorsFound = true
}
}
if (!gradleApiFound) {
throw Exception("API documentation does not include Gradle API")
}
if (!gradleKotlinDslApiFound) {
throw Exception("API documentation does not include Gradle Kotlin DSL")
}
if (!gradleKotlinDslGeneratedApiFound) {
throw Exception("API documentation does not include *generated* Gradle Kotlin DSL")
}
if (!gradlePluginsBlockAccessorsFound) {
throw Exception("API documentation does not include *generated* Gradle plugins { core } accessors")
}
if (!gradlePluginsAccessorsFound) {
throw Exception("API documentation does not include *generated* Core Gradle Plugins extensions accessors")
}
if (filesWithErrorClass.isNotEmpty()) {
throw Exception("<ERROR CLASS> found in ${filesWithErrorClass.size} files:\n ${filesWithErrorClass.joinToString("\n ")}")
}
}
}
// Lifecycle
val cleanBuildWithCorePlugins by creating(GradleBuild::class) {
dir = buildWithCorePluginsDir
tasks = listOf("clean")
}
"clean" {
dependsOn(cleanBuildWithCorePlugins)
}
"assemble" {
dependsOn(apiDocumentation)
}
"check" {
dependsOn(checkApiDocumentation)
}
// Publishing
githubPages {
pages.apply {
from("$buildDir/docs/dokka")
from("$buildDir/docs/gradle")
from("src/pages")
}
commitMessage = "Updating gh-pages"
}
"prepareGhPages" {
description = "Stages documentation locally."
dependsOn("assemble")
}
"publishGhPages" {
description = "Publishes documentation to production."
dependsOn("check")
}
// Global tasks configuration
withType<GradleBuild> {
startParameter.showStacktrace = ShowStacktrace.ALWAYS
}
}