-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
140 lines (120 loc) · 3.63 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
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
alias(libs.plugins.kotlinGradlePlugin) apply false
alias(libs.plugins.kotlinBinaryCompatibilityPlugin) apply false
alias(libs.plugins.mavenPublishGradlePlugin) apply false
alias(libs.plugins.versionsGradlePlugin)
alias(libs.plugins.versionCatalogUpdateGradlePlugin)
alias(libs.plugins.dokka)
}
repositories {
mavenCentral()
gradlePluginPortal()
}
buildscript {
repositories {
mavenCentral()
}
}
subprojects {
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
repositories {
mavenCentral()
}
apply(plugin = "java")
apply(plugin = "kotlin")
apply(plugin = rootProject.project.libs.plugins.kotlinBinaryCompatibilityPlugin.get().pluginId)
apply(plugin = rootProject.project.libs.plugins.mavenPublishGradlePlugin.get().pluginId)
configure<JavaPluginExtension> {
withSourcesJar()
withJavadocJar()
}
plugins.withId("com.vanniktech.maven.publish.base") {
val publishingExtension = extensions.getByType(PublishingExtension::class.java)
configure<com.vanniktech.maven.publish.MavenPublishBaseExtension> {
pomFromGradleProperties()
publishToMavenCentral(com.vanniktech.maven.publish.SonatypeHost.DEFAULT, true)
signAllPublications()
}
publishingExtension.publications.create<MavenPublication>("maven") {
from(components["java"])
}
}
apply(plugin = "version-catalog")
// Only apply if the project has the kotlin plugin added:
plugins.withType<KotlinPluginWrapper> {
val compileKotlin by tasks.getting(KotlinCompile::class) {
kotlinOptions {
jvmTarget = "11"
allWarningsAsErrors = true
}
}
val compileTestKotlin by tasks.getting(KotlinCompile::class) {
kotlinOptions {
jvmTarget = "11"
allWarningsAsErrors = true
}
}
dependencies {
add("testImplementation", project.rootProject.libs.junitApi)
add("testRuntimeOnly", project.rootProject.libs.junitEngine)
}
tasks.withType<GenerateModuleMetadata> {
suppressedValidationErrors.add("enforced-platform")
}
}
tasks.withType<Test> {
dependsOn("apiCheck")
useJUnitPlatform()
testLogging {
events("started", "passed", "skipped", "failed")
exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = false
}
}
apply(plugin = "com.github.ben-manes.versions")
tasks.withType<com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask> {
revision = "release"
resolutionStrategy {
componentSelection {
all {
if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
reject("Release candidate")
}
}
}
}
}
}
fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}
// this needs to be defined here for the versionCatalogUpdate
tasks.withType<com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask> {
revision = "release"
resolutionStrategy {
componentSelection {
all {
if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
reject("Release candidate")
}
}
}
}
}
versionCatalogUpdate {
/**
* Use @pin and @keep in gradle/lib.versions.toml instead of defining here
*/
sortByKey.set(true)
}