forked from pinterest/ktlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
168 lines (147 loc) · 4.85 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
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
plugins {
id 'org.jetbrains.kotlin.jvm' apply false
id 'com.github.breadmoirai.github-release'
}
ext.versions = [
'kotlin': gradle.ext.isKotlinDev ? "1.5.30-RC" : "1.5.20",
'gradle': '7.2',
'gradle-sha256': 'f581709a9c35e9cb92e16f585d2c4bc99b2b1a5f85d2badbd3dc6bff59e1e6dd'
]
ext.deps = [
'kotlin' : [
'compiler': "org.jetbrains.kotlin:kotlin-compiler-embeddable:${versions.kotlin}"
],
'klob' : 'com.github.shyiko.klob:klob:0.2.1',
ec4j : 'org.ec4j.core:ec4j-core:0.3.0',
'picocli' : 'info.picocli:picocli:3.9.6',
// Testing libraries
'junit' : 'junit:junit:4.13.1',
'assertj' : 'org.assertj:assertj-core:3.12.2',
'sarif4k' : 'io.github.detekt.sarif4k:sarif4k:0.0.1',
'jimfs' : 'com.google.jimfs:jimfs:1.1'
]
if (gradle.ext.isKotlinDev) {
allprojects { p ->
String definedVersion = p.ext."VERSION_NAME".minus("-SNAPSHOT")
p.ext."VERSION_NAME" = "$definedVersion-kotlin-dev-SNAPSHOT".toString()
}
}
configurations {
ktlint
}
dependencies {
ktlint project(':ktlint')
}
task ktlint(type: JavaExec, group: LifecycleBasePlugin.VERIFICATION_GROUP) {
description = "Check Kotlin code style."
classpath = configurations.ktlint
main = 'com.pinterest.ktlint.Main'
args '**/src/**/*.kt', '--baseline=ktlint-baseline.xml', '--verbose'
}
allprojects {
repositories {
mavenCentral()
gradlePluginPortal()
}
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
kotlinOptions {
jvmTarget = '1.8'
apiVersion = '1.3'
useIR = true
freeCompilerArgs = ["-Xopt-in=kotlin.RequiresOptIn"]
}
}
}
subprojects { subProject ->
// Do not enabling explicit api for cli project
if (subProject.name != "ktlint") {
subProject.plugins.withId("org.jetbrains.kotlin.jvm") {
subProject.extensions.configure("kotlin") { ext ->
ext.explicitApi = 'warning'
}
}
}
}
/**
* Configures "wrapper" task to use specific Gradle version and distribution type.
*/
tasks.withType(Wrapper.class).configureEach {
gradleVersion = versions.gradle
distributionType = Wrapper.DistributionType.BIN
}
// Deployment tasks
String getGithubToken() {
if (project.hasProperty("servers.github.privKey")) {
return project.'servers.github.privKey'
} else {
logger.warn("No github token specified")
return ""
}
}
// Explicitly adding dependency on "shadowJarExecutable" as Gradle does not it set via "releaseAssets" property
tasks.named("githubRelease") {
dependsOn { project(":ktlint").tasks.named("shadowJarExecutable") }
}
githubRelease {
token getGithubToken()
owner "pinterest"
repo "ktlint"
tagName project.properties['VERSION_NAME']
releaseName project.properties['VERSION_NAME']
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
project(":ktlint").tasks.named("shadowJarExecutable").get()
.outputs
.files
.getFiles()
.first()
.parentFile
.listFiles()
})
overwrite true
dryRun false
body {
String changelog = project.file("CHANGELOG.md").text
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".
def announceTask = tasks.register("announceRelease", Exec.class) { announceTask ->
group = "Help"
description = "Runs .announce script"
subprojects
.findAll { !it.name.contains("ktlint-ruleset-template") }
.each { subproject ->
announceTask.dependsOn subproject.tasks.named("publishMavenPublicationToMavenCentralRepository")
}
commandLine './.announce', '-y'
environment VERSION: "${project.'VERSION_NAME'}"
environment GITHUB_TOKEN: "${getGithubToken()}"
}
def homebrewTask = tasks.register("homebrewBumpFormula", Exec.class) { homebrewTask ->
group "Help"
description "Runs brew bump-forumula-pr"
commandLine './.homebrew'
environment VERSION: "${project.'VERSION_NAME'}"
dependsOn(tasks.named("githubRelease"))
}
tasks.register("publishNewRelease", DefaultTask.class) {
group = "Help"
description = "Triggers uploading new archives and publish announcements"
dependsOn(announceTask, homebrewTask, tasks.named("githubRelease"))
}
tasks.withType(Wrapper).configureEach {
gradleVersion = versions.'gradle'
distributionSha256Sum = versions.'gradle-sha256'
distributionType = Wrapper.DistributionType.BIN
}