forked from pinterest/ktlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
123 lines (108 loc) · 4.04 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
plugins {
id(libs.plugins.kotlin.jvm.get().pluginId) apply false
alias(libs.plugins.checksum)
alias(libs.plugins.shadow)
alias(libs.plugins.githubRelease)
}
val isKotlinDev: Boolean = project.hasProperty("isKotlinDev")
allprojects {
if (isKotlinDev) {
val definedVersion = ext["VERSION_NAME"].toString().removeSuffix("-SNAPSHOT")
ext["VERSION_NAME"] = "$definedVersion-kotlin-dev-SNAPSHOT"
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
}
val ktlint: Configuration = configurations.create("ktlint")
dependencies {
ktlint(projects.ktlint)
}
tasks.register<JavaExec>("ktlint") {
group = LifecycleBasePlugin.VERIFICATION_GROUP
description = "Check Kotlin code style including experimental rules."
classpath = ktlint
mainClass.set("com.pinterest.ktlint.Main")
// Experimental rules run by default run on the ktlint code base itself. Experimental rules should not be released if
// we are not pleased ourselves with the results on the ktlint code base.
// Sources in "ktlint/src/test/resources" are excluded as those source contain lint errors that have to be detected by
// unit tests and should not be reported/fixed.
args(
"**/src/**/*.kt",
"**.kts",
"!**/build/**",
"!ktlint/src/test/resources/**",
"--baseline=ktlint/src/test/resources/test-baseline.xml",
"--experimental",
"--verbose"
)
}
// Deployment tasks
val githubToken: String = if (project.hasProperty("servers.github.privKey")) {
project.property("servers.github.privKey").toString()
} else {
logger.warn("No github token specified")
""
}
val shadowJarExecutable: Task by lazy {
projects.ktlint.dependencyProject.tasks["shadowJarExecutable"]
}
// Explicitly adding dependency on "shadowJarExecutable" as Gradle does not it set via "releaseAssets" property
tasks.githubRelease {
dependsOn({
shadowJarExecutable
})
}
githubRelease {
token(githubToken)
owner("pinterest")
repo("ktlint")
tagName(project.property("VERSION_NAME").toString())
releaseName(project.property("VERSION_NAME").toString())
releaseAssets(
project.files(
{
// "shadowJarExecutableChecksum" task does not declare checksum files
// as output, only the whole output directory. As it uses the same directory
// as "shadowJarExecutable" - just pass all the files from that directory
shadowJarExecutable.outputs.files.files.first().parentFile.listFiles()
}
)
)
overwrite(true)
dryRun(false)
body {
var changelog = project.file("CHANGELOG.md").readText()
changelog = changelog.substring(changelog.indexOf("## "))
// 1 in indexOf here to skip first "## [" occurence
changelog.substring(0, changelog.indexOf("## [", 1))
}
}
// Put "servers.github.privKey" in "$HOME/.gradle/gradle.properties".
val announceRelease by tasks.registering(Exec::class) {
group = "Help"
description = "Runs .announce script"
subprojects.filter { !it.name.contains("ktlint-ruleset-template") }.forEach { subproject ->
dependsOn(subproject.tasks["publishMavenPublicationToMavenCentralRepository"])
}
commandLine("./.announce", "-y")
environment("VERSION" to "${project.property("VERSION_NAME")}")
environment("GITHUB_TOKEN" to githubToken)
}
val homebrewBumpFormula by tasks.registering(Exec::class) {
group = "Help"
description = "Runs brew bump-forumula-pr"
commandLine("./.homebrew")
environment("VERSION" to "${project.property("VERSION_NAME")}")
dependsOn(tasks.githubRelease)
}
tasks.register<DefaultTask>("publishNewRelease") {
group = "Help"
description = "Triggers uploading new archives and publish announcements"
dependsOn(announceRelease, homebrewBumpFormula, tasks.githubRelease)
}
tasks.wrapper {
gradleVersion = libs.versions.gradle.get()
distributionSha256Sum = libs.versions.gradleSha256.get()
distributionType = Wrapper.DistributionType.BIN
}