-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
178 lines (157 loc) · 5.63 KB
/
build.gradle.kts
File metadata and controls
178 lines (157 loc) · 5.63 KB
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
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.util.Base64
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.dokka)
alias(libs.plugins.dependencyUpdates)
id("signing")
id("maven-publish")
}
group = "de.halfbit"
version = "1.3"
repositories {
mavenCentral()
}
kotlin {
explicitApi()
jvm()
linuxX64()
linuxArm64()
mingwX64()
macosX64()
macosArm64()
js {
browser {
testTask {
useKarma {
useFirefoxHeadless()
}
}
}
nodejs()
}
iosX64()
iosArm64()
iosSimulatorArm64()
sourceSets {
commonTest {
dependencies {
implementation(libs.kotlin.test)
}
}
}
}
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
}
}
val canSignArtifacts = project.hasProperty("signing.keyId")
if (canSignArtifacts) {
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
dependsOn(tasks.named("dokkaGeneratePublicationHtml"))
from(layout.buildDirectory.dir("dokka/html"))
}
publishing {
repositories {
maven {
name = "local"
url = uri("${layout.buildDirectory}/repository")
}
maven {
name = "central"
url = uri("https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/")
credentials {
username = project.getPropertyOrEmpty("publishing.nexus.user")
password = project.getPropertyOrEmpty("publishing.nexus.password")
}
}
}
publications.withType<MavenPublication> {
artifact(javadocJar.get())
pom {
name.set(rootProject.name)
description.set("Tiny Kotlin Multiplatform library for parsing and building CSV strings")
url.set("https://github.com/sergejsha/${rootProject.name}")
licenses {
license {
name.set("Apache-2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("halfbit")
name.set("Sergej Shafarenka")
organization.set("Halfbit GmbH")
organizationUrl.set("http://www.halfbit.de")
}
}
scm {
connection.set("scm:git:git@github.com:sergejsha/${rootProject.name}.git")
developerConnection.set("scm:git:ssh://github.com:sergejsha/${rootProject.name}.git")
url.set("https://github.com/sergejsha/${rootProject.name}")
}
}
}
}
signing {
publishing.publications.withType<MavenPublication>().configureEach {
sign(this)
}
}
afterEvaluate {
// fix for: https://github.com/gradle/gradle/issues/26091
// https://youtrack.jetbrains.com/issue/KT-46466 is fixed
tasks.withType<AbstractPublishToMaven>().configureEach {
dependsOn(project.tasks.withType(Sign::class.java))
}
}
tasks.register("releaseToMavenCentral") {
group = "publishing"
description = "Publishes to staging and manually uploads to Maven Central"
dependsOn("publishAllPublicationsToCentralRepository")
doLast {
val username = project.getPropertyOrEmpty("publishing.nexus.user")
val password = project.getPropertyOrEmpty("publishing.nexus.password")
val bearer = Base64.getEncoder().encodeToString("$username:$password".toByteArray())
val request = HttpRequest.newBuilder()
.uri(URI.create("https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/de.halfbit"))
.header("Authorization", "Bearer $bearer")
.POST(HttpRequest.BodyPublishers.noBody())
.build()
val response = HttpClient
.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString())
if (response.statusCode() != 200) {
throw GradleException("Manual upload failed ${response.statusCode()}:[${response.body()}]")
} else {
println(
"✅ Published and uploaded to Maven Central successfully." +
" Release to public at https://central.sonatype.com/publishing"
)
}
}
}
}
private fun Project.getPropertyOrEmpty(name: String): String =
if (hasProperty(name)) property(name) as String? ?: "" else ""
// -- START: Check version only accepts stable versions
private val unstableVersionRegex = "[0-9,.v-]+(-r)?(.*)".toRegex()
private fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
return !stableKeyword && !unstableVersionRegex.matches(version)
}
tasks.withType<com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask> {
rejectVersionIf {
isNonStable(candidate.version) && !isNonStable(currentVersion)
}
gradleReleaseChannel = "stable"
}
// -- END