-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
136 lines (115 loc) · 4 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
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
plugins {
kotlin("jvm") version "1.7.0"
id("org.jlleitschuh.gradle.ktlint") version "10.3.0"
id("com.github.ben-manes.versions") version "0.42.0"
`maven-publish`
}
group = "com.github.ekenstein"
version = "0.1.1"
val kotlinJvmTarget = "1.8"
val junitVersion by extra("5.8.2")
val kotlinVersion by extra("1.7.0")
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
testImplementation(kotlin("test"))
testImplementation("org.junit.jupiter", "junit-jupiter-params", junitVersion)
testImplementation("org.junit.jupiter", "junit-jupiter-api", junitVersion)
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", junitVersion)
}
tasks {
dependencyUpdates {
rejectVersionIf(UpgradeToUnstableFilter())
}
val dependencyUpdateSentinel = register<DependencyUpdateSentinel>("dependencyUpdateSentinel", buildDir)
dependencyUpdateSentinel.configure {
dependsOn(dependencyUpdates)
}
withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "1.8"
}
compileKotlin {
kotlinOptions {
jvmTarget = kotlinJvmTarget
freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn")
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = kotlinJvmTarget
freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn")
}
}
compileJava {
sourceCompatibility = kotlinJvmTarget
targetCompatibility = kotlinJvmTarget
}
compileTestJava {
sourceCompatibility = kotlinJvmTarget
targetCompatibility = kotlinJvmTarget
}
check {
dependsOn(test)
dependsOn(ktlintCheck)
dependsOn(dependencyUpdateSentinel)
}
test {
useJUnitPlatform()
}
}
ktlint {
version.set("0.45.2")
}
publishing {
publications {
create<MavenPublication>("ktgtp") {
groupId = project.group.toString()
artifactId = "ktgtp"
version = project.version.toString()
from(components["kotlin"])
artifact(tasks.kotlinSourcesJar)
pom {
name.set("ktgtp")
description.set("GTP engine communication DSL")
url.set("https://github.com/Ekenstein/ktgtp")
licenses {
license {
name.set("MIT")
url.set("https://github.com/Ekenstein/ktgtp/blob/main/LICENSE")
}
}
}
}
}
}
class UpgradeToUnstableFilter : com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentFilter {
override fun reject(cs: ComponentSelectionWithCurrent) = 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.")
}
}
}
}