-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
501 lines (452 loc) · 16.1 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
/*
* Copyright 2020 Patrick Leitermann
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.jfrog.bintray.gradle.BintrayExtension.GpgConfig
import com.jfrog.bintray.gradle.BintrayExtension.PackageConfig
import com.jfrog.bintray.gradle.BintrayExtension.VersionConfig
import java.net.URL
import java.util.Date
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
/**
* Applies the Gradle plugins used during the build.
*/
plugins {
/**
* Plugin for building custom Gradle plugins.
*/
`java-gradle-plugin`
/**
* Plugin for publishing Maven artifacts.
*/
`maven-publish`
/**
* Gradle plugin for publishing Maven artifacts to the Bintray repository.
*/
id("com.jfrog.bintray") version "1.8.4"
/**
* Gradle plugin for publishing custom Gradle plugins to
* the Gradle Plugin Portal.
*/
id("com.gradle.plugin-publish") version "0.10.1"
/**
* Plugin for generating a documentation based on the source
* code comments at the Kotlin files.
*/
id("org.jetbrains.dokka") version "1.4.10.2"
/**
* Plugin for checking the coding-conventions of *.kt and *.kts files.
*/
id("org.gradle.kotlin-dsl.ktlint-convention") version "0.5.0"
/**
* License manager for testing and applying the content of a 'LICENSE-HEADER' file
* at the headers of various files.
*/
id("net.minecrell.licenser") version "0.4.1"
/**
* Plugin that configures the project as 'Implementation' project.
*/
id("com.github.ptkltm.development.fullstackproject.implementation")
/**
* Plugin for the configuration of the Kotlin infrastructure
* for building Kotlin code based on the Java Virtual Machine.
*/
kotlin(module = "jvm") version "1.4.10"
}
/**
* Sets the description of the project.
*/
description = "Plugins for the automated management of a full stack project being based on multiple technologies."
/**
* Sets the version of the project.
*/
version = "0.1.0"
/**
* The labels of the project.
*/
val projectLabels = listOf("automation", "fullstack", "subprojects", "subbuilds", "compositebuilds", "build")
/**
* The name of the publication for the ´maven-publish´ plugin that is referenced by the 'bintray' configuration
* of the 'com.jfrog.bintray' plugin.
*/
val publicationName = "pluginMaven"
/**
* Configures the repositories.
*/
repositories {
/**
* Repository that provides artifacts published to the Gradle Plugin Portal.
*/
gradlePluginPortal()
}
/**
* Closure of the configurations being used by the 'dependencies' block for the separation
* of source sets.
*/
configurations {
/**
* Extracts the value for the key 'junitVersion' from the projects's properties
* defined in the file 'gradle.properties'.
*/
val junitVersion: String by project
/**
* Changes the version of all dependencies with the group 'org.junit.jupiter' in all
* configurations to the 'junitVersion' project property defined in the gradle.properties file.
*
* That's necessary because the 'test-junit5' module of Kotlin has a transitive dependency to
* 'org.unit.jupiter' dependencies with the version 5.0.0, but the @TempDir annotation being used
* in a test class is only supported at version 5.4.0.
*/
all {
resolutionStrategy.eachDependency {
if (requested.group == "org.junit.jupiter") {
useVersion(junitVersion)
because("@TempDir is only supported since JUnit 5.4.0.")
}
}
}
}
/**
* Configures the dependencies of the project.
*/
dependencies {
/**
* Test dependency to the JUnit 5 Jupiter supported framework for Kotlin.
*/
testImplementation(dependencyNotation = kotlin(module = "test-junit5"))
/**
* Extracts the value for the key 'junitVersion' from the project's properties
* defined in the file 'gradle.properties'.
*/
val junitVersion: String by project
/**
* Runtime dependency to the JUnit 5 Jupiter engine, that's needed for
* the execution of the 'test' task with the [Test.useJUnitPlatform]
* configuration.
*/
testRuntimeOnly(
group = "org.junit.jupiter",
name = "junit-jupiter-engine",
version = junitVersion
)
}
/**
* Configuration of the custom Gradle plugin.
*
* Automatically generates two Gradle plugin descriptor for the id
* 'com.github.pktltm.development.fullstackproject.domain' and the implementation class
* 'com.github.pktltm.development.fullstackproject.gradleplugin.FullStackProjectDomainGradlePlugin' and the
* id 'com.github.pktltm.development.fullstackproject.implementation' with the implementation class
* 'com.github.pktltm.development.fullstackproject.gradleplugin.FullStackProjectImplementationGradlePlugin'
* at the output jar, so that the Gradle plugin system is able to apply to solve the plugin
* by it's id after it's applied to a build script.
*/
gradlePlugin {
plugins {
/**
* Reusable method for defining Gradle custom plugins staring with the id prefix
* 'com.github.ptkltm.development.fullstackproject.'..
*
* @param [pluginSuffix] The suffix of the plugin.
* @sample [pluginSuffix] 'Implementation' for the plugin id
* 'com.github.ptkltm.development.fullstackproject.implementation' and 'Domain' for the plugin id
* 'com.github.ptkltm.development.fullstackproject.domain'.
*/
fun createFullStackProjectGradlePlugin(
pluginSuffix: String
) {
create("fullStackProject${pluginSuffix}Plugin") {
id = "${project.name.substringBeforeLast(delimiter = '.')}.${pluginSuffix.toLowerCase()}"
implementationClass = "${project.name}.FullStackProject${pluginSuffix}GradlePlugin"
}
}
/**
* Creates the custom Gradle plugin with the id 'com.github.ptkltm.development.fullstackproject.implementation'.
*/
createFullStackProjectGradlePlugin(pluginSuffix = "Implementation")
/**
* Creates the custom Gradle plugin with the id 'com.github.ptkltm.development.fullstackproject.domain'.
*/
createFullStackProjectGradlePlugin(pluginSuffix = "Domain")
}
}
/**
* Configuration of the meta data for publishing the Gradle plugin to the
* Gradle Plugin portal.
*/
pluginBundle {
/**
* Extracts the value for the key 'repositoryUrl' from the projects's properties
* defined in the file 'gradle.properties'.
*/
val repositoryUrl: String by project
website = repositoryUrl
vcsUrl = repositoryUrl
description = project.description
tags = projectLabels
plugins {
maybeCreate("fullStackProjectPlugin").apply {
displayName = project.findProperty("projectDisplayName").toString()
}
}
/**
* Removes the 'gradle.plugin' prefix from the group of the Maven artifact
* of the plugin.
*/
mavenCoordinates {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
}
}
/**
* Configures the metadata of the pom.xml for the Maven publication.
*/
publishing {
publications {
create(publicationName, MavenPublication::class) {
pom {
/**
* Extracts the value for the key 'projectDisplayName' from the projects's properties
* defined in the file 'gradle.properties'.
*/
val projectDisplayName: String by project
/**
* Extracts the value for the key 'repositoryUrl' from the projects's properties
* defined in the file 'gradle.properties'.
*/
val repositoryUrl: String by project
/**
* Extracts the value for the key 'developerName' from the projects's properties
* defined in the file 'gradle.properties'.
*/
val developerName: String by project
/**
* Extracts the value for the key 'developerEmail' from the projects's properties
* defined in the file 'gradle.properties'.
*/
val developerEmail: String by project
name.set(projectDisplayName)
description.set(project.description)
inceptionYear.set("2020")
organization {
name.set(developerName)
url.set("https://github.com/ptkltm")
}
developers {
developer {
name.set(developerName)
email.set(developerEmail)
}
}
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
issueManagement {
system.set("GitHub")
url.set("$repositoryUrl/issues")
}
scm {
url.set(repositoryUrl)
tag.set(project.version.toString())
}
}
afterEvaluate {
val publishPluginJar by tasks.getting(Jar::class)
val publishPluginJavaDocsJar by tasks.getting(Jar::class)
artifact(publishPluginJar)
artifact(publishPluginJavaDocsJar)
}
}
}
}
/**
* Configuration of the plugin publication to the Bintray repository.
* If the plugin should be published to Bintray the Gradle task 'bintrayUpload' must be executed with the
* command line parameters
* '-PisReleasePublication=true -PbintrayUser=<username> -PbintrayKey=<apikey> -PgpgPassphrase=<passphrase>'.
*
*/
bintray {
/**
* Extracts a bintray value from either the property in the gradle.properties.kts file
* or the environment variable.
*
* For the properties in the gradle.properties.kts file camel-case is used (e. g. 'bintrayUser' for 'user')
* and for environment variables upper snake-case is used (e. g. 'BINTRAY_USER' for 'user').
*
* @receiver The key being prefixed with either 'bintray' for the build.gradle.kts properties
* or 'BINTRAY_' for the environment variable approach.
*/
fun String.extractValue(): String? {
val propertyName = "bintray${capitalize()}"
return if (hasProperty(propertyName))
property(propertyName)?.toString()
else
System.getenv("BINTRAY_${toUpperCase()}")
}
user = "user".extractValue()
key = "key".extractValue()
setPublications(publicationName)
/**
* Extracts the value for the key 'isReleasePublication' from the project's properties
* defined in the file 'gradle.properties'.
*/
val isReleasePublication: String by project
publish = "true" == isReleasePublication
pkg(closureOf<PackageConfig> {
name = project.name
repo = name.substringBeforeLast(delimiter = '.')
.substringBeforeLast(delimiter = '.')
version(closureOf<VersionConfig> {
name = project.version.toString()
desc = project.description
released = Date().toString()
vcsTag = name
gpg(closureOf<GpgConfig> {
if (publish) {
/**
* Extracts the value for the key 'gpgPassphrase' from the project's properties
* defined in the file 'gradle.properties'.
*/
val gpgPassphrase: String by project
passphrase = gpgPassphrase
}
sign = true
})
})
setLabels(*listOf("gradle", "gradleplugin").union(other = projectLabels).toTypedArray())
setLicenses("Apache-2.0")
/**
* Extracts the value for the key 'repositoryUrl' from the projects's properties
* defined in the file 'gradle.properties'.
*/
val repositoryUrl: String by project
/**
* Extracts the value for the key 'gitHubRepository' from the projects's properties
* defined in the file 'gradle.properties'.
*/
val gitHubRepository: String by project
vcsUrl = "$repositoryUrl.git"
githubRepo = gitHubRepository
websiteUrl = repositoryUrl
issueTrackerUrl = "$repositoryUrl/issues"
publicDownloadNumbers = true
})
}
/**
* Checks that the content of the 'LICENSE-HEADER' file is applied to all
* recursive files with the *.java and *.kt extensions and the files
* build.gradle.kts, settings.gradle.kts and gradle.properties at the
* root level of the project.
*/
license {
header = file("LICENSE-HEADER")
include("**/*.java", "**/*.kt")
tasks {
create("gradle") {
files = project.files(
"build.gradle.kts",
"settings.gradle.kts",
"gradle.properties"
)
}
}
}
/**
* Configures the tasks of the project.
*/
tasks {
/**
* Configuration of all Kotlin compile tasks to use the jvmTarget 1.8.
*/
withType(KotlinCompile::class) {
kotlinOptions {
/**
* Extracts the value for the key 'kotlinJvmTarget' from the project's properties
* defined in the file 'gradle.properties'.
*/
val kotlinJvmTarget: String by project
jvmTarget = kotlinJvmTarget
}
}
/**
* Configures all Java compile tasks to use Java 1.8.
*/
withType(JavaCompile::class) {
val javaVersion = JavaVersion.VERSION_1_8.toString()
targetCompatibility = javaVersion
sourceCompatibility = javaVersion
}
/**
* Enables Junit 5 Jupiter during the test runtime.
*/
test {
useJUnitPlatform()
}
/**
* Configures the Gradle wrapper with the version '6.7'.
*/
wrapper {
gradleVersion = "6.7"
}
}
/**
* Closure for the initialization of the Gradle project after it's fully
* evaluated.
*/
afterEvaluate {
/**
* Configures the tasks of the project.
*/
tasks {
/**
* Disables the 'javadoc' task.
*/
val javadoc by getting(Javadoc::class) {
enabled = false
}
/**
* Produces the javadoc documentation for the Kotlin files inside the
* output directory of the disabled 'javadoc' task.
*/
val dokkaJavadoc by getting(DokkaTask::class) {
outputDirectory.set(javadoc.destinationDir)
dokkaSourceSets {
configureEach {
externalDocumentationLink {
val externalGradleJavaDocUrl = "https://docs.gradle.org/current/javadoc/"
url.set(URL(externalGradleJavaDocUrl))
packageListUrl.set(URL("${externalGradleJavaDocUrl}package-list"))
}
skipDeprecated.set(true)
skipEmptyPackages.set(true)
reportUndocumented.set(true)
}
}
}
/**
* Instead of the output of the disabled 'javadoc' task, the JavaDoc jar
* now uses the 'dokkaJavadoc' output by depending on the task.
*/
"publishPluginJavaDocsJar" {
dependsOn(dokkaJavadoc)
}
}
}