-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
222 lines (187 loc) · 6.57 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
import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentFilter
import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionWithCurrent
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.nio.file.Paths
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.inputStream
val kotlinVersion by extra("1.7.10")
val junitVersion by extra("5.8.2")
plugins {
kotlin("jvm") version "1.7.10"
id("org.jetbrains.dokka") version "1.7.10"
id("org.jlleitschuh.gradle.ktlint") version "10.3.0"
id("com.github.ben-manes.versions") version "0.42.0"
antlr
`maven-publish`
jacoco
}
group = "com.github.ekenstein"
version = "2.2.6"
val kotlinJvmTarget = "1.8"
repositories {
mavenCentral()
}
val dokkaHtml by tasks.getting(org.jetbrains.dokka.gradle.DokkaTask::class)
val javadocJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
dependsOn(dokkaHtml)
archiveClassifier.set("javadoc")
from(dokkaHtml.outputDirectory)
}
dependencies {
implementation("org.jetbrains.kotlin", "kotlin-stdlib", kotlinVersion)
testImplementation("org.jetbrains.kotlin", "kotlin-test", kotlinVersion)
antlr("org.antlr", "antlr4", "4.10.1")
implementation("org.antlr", "antlr4-runtime", "4.10.1")
testImplementation("org.junit.jupiter", "junit-jupiter-params", junitVersion)
testImplementation("org.junit.jupiter", "junit-jupiter-api", junitVersion)
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", junitVersion)
}
// Exclude antlr4 from transitive dependencies (https://github.com/gradle/gradle/issues/820)
configurations[JavaPlugin.API_CONFIGURATION_NAME].let { apiConfiguration ->
apiConfiguration.setExtendsFrom(apiConfiguration.extendsFrom.filter { it.name != "antlr" })
}
tasks {
dependencyUpdates {
rejectVersionIf {
UpgradeToUnstableFilter().reject(this) || IgnoredDependencyFilter().reject(this)
}
}
val dependencyUpdateSentinel = register<DependencyUpdateSentinel>("dependencyUpdateSentinel", buildDir)
dependencyUpdateSentinel.configure {
dependsOn(dependencyUpdates)
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
generateGrammarSource {
outputDirectory = Paths
.get("build", "generated-src", "antlr", "main", "com", "github", "ekenstein", "sgf", "parser")
.toFile()
mustRunAfter(ktlintMainSourceSetCheck)
mustRunAfter(dokkaHtml)
}
generateTestGrammarSource {
mustRunAfter(ktlintTestSourceSetCheck)
}
kotlinSourcesJar {
dependsOn("generateGrammarSource")
}
compileKotlin {
dependsOn(generateGrammarSource)
kotlinOptions {
jvmTarget = kotlinJvmTarget
freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn")
}
}
compileTestKotlin {
dependsOn(generateTestGrammarSource)
kotlinOptions {
jvmTarget = kotlinJvmTarget
freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn")
}
}
listOf(compileJava, compileTestJava).map { task ->
task {
sourceCompatibility = kotlinJvmTarget
targetCompatibility = kotlinJvmTarget
}
}
build {
dependsOn("javadocJar")
}
check {
dependsOn(test)
dependsOn(ktlintCheck)
dependsOn(dependencyUpdateSentinel)
dependsOn(jacocoTestCoverageVerification)
}
test {
useJUnitPlatform()
finalizedBy(jacocoTestReport)
}
jacocoTestReport {
dependsOn(test)
// CSV report for coverage badge
reports.csv.required.set(true)
// Exclude generated code from coverage report
classDirectories.setFrom(
files(
classDirectories.files.filter { !it.path.contains("build/classes/java") }.map { file ->
fileTree(file).exclude {
it.name.contains("special\$\$inlined")
}
}
)
)
}
jacocoTestCoverageVerification {
dependsOn(jacocoTestReport)
violationRules {
rule {
limit {
minimum = BigDecimal(0.8)
}
}
}
}
}
ktlint {
version.set("0.45.2")
}
publishing {
publications {
create<MavenPublication>("haengma") {
groupId = project.group.toString()
artifactId = "haengma"
version = project.version.toString()
from(components["kotlin"])
artifact(javadocJar)
artifact(tasks.kotlinSourcesJar)
pom {
name.set("haengma")
description.set("Simple SGF parser")
url.set("https://github.com/Ekenstein/haengma")
licenses {
license {
name.set("MIT")
url.set("https://github.com/Ekenstein/haengma/blob/main/LICENSE")
}
}
}
}
}
}
class IgnoredDependencyFilter : ComponentFilter {
private val ignoredDependencies = mapOf(
"ktlint" to listOf("0.46.0", "0.46.1") // doesn't currently work.
)
override fun reject(p0: ComponentSelectionWithCurrent): Boolean {
return ignoredDependencies[p0.candidate.module].orEmpty().contains(p0.candidate.version)
}
}
class UpgradeToUnstableFilter : ComponentFilter {
override fun reject(cs: ComponentSelectionWithCurrent): Boolean {
return reject(cs.currentVersion, cs.candidate.version)
}
private fun reject(old: String, new: String): Boolean {
return !isStable(new) && isStable(old) // no unstable proposals for stable dependencies
}
private fun isStable(version: String): Boolean {
val stableKeyword = setOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
val stablePattern = version.matches(Regex("""^[0-9,.v-]+(-r)?$"""))
return stableKeyword || stablePattern
}
}
abstract class DependencyUpdateSentinel @Inject constructor(private val buildDir: File) : DefaultTask() {
@ExperimentalPathApi
@TaskAction
fun check() {
val updateIndicator = "The following dependencies have later milestone versions:"
val report = Paths.get(buildDir.toString(), "dependencyUpdates", "report.txt")
report.inputStream().bufferedReader().use { reader ->
if (reader.lines().anyMatch { it == updateIndicator }) {
throw GradleException("Dependency updates are available.")
}
}
}
}