-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle.kts
236 lines (204 loc) · 7.56 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import org.jetbrains.dokka.gradle.DokkaTask
import javax.xml.parsers.DocumentBuilderFactory
plugins {
// NOTE: Intentionally older version to maximize compatibility with projects in the wild
// Going much older and this buildscript won't compile
kotlin("multiplatform") version "1.7.21"
id("org.jetbrains.dokka") version "1.9.20"
id("org.jetbrains.kotlinx.kover") version "0.7.6"
`maven-publish`
signing
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
id("com.android.library") version "8.3.0"
}
repositories {
mavenCentral()
google()
}
group = "com.varabyte.truthish"
version = "1.0.1"
tasks.register("printLineCoverage") {
group = "verification" // Put into the same group as the `kover` tasks
dependsOn("koverXmlReport")
doLast {
val report = layout.buildDirectory.file("reports/kover/report.xml").get().asFile
val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(report)
val rootNode = doc.firstChild
var childNode = rootNode.firstChild
var coveragePercent = 0.0
while (childNode != null) {
if (childNode.nodeName == "counter") {
val typeAttr = childNode.attributes.getNamedItem("type")
if (typeAttr.textContent == "LINE") {
val missedAttr = childNode.attributes.getNamedItem("missed")
val coveredAttr = childNode.attributes.getNamedItem("covered")
val missed = missedAttr.textContent.toLong()
val covered = coveredAttr.textContent.toLong()
coveragePercent = (covered * 100.0) / (missed + covered)
break
}
}
childNode = childNode.nextSibling
}
println("%.1f".format(coveragePercent))
}
}
kotlin {
jvmToolchain(8) // Used by Android to set JDK version used by kotlin compilation
jvm {
val main by compilations.getting {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js(IR) {
browser()
}
linuxX64()
macosArm64() // Mac M1+
macosX64() // Mac Intel
mingwX64() // Windows
iosX64() // iOS Intel
iosArm64() // iOS M1+
iosSimulatorArm64()
android {
publishLibraryVariants("release")
}
sourceSets {
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
}
}
android {
namespace = "com.varabyte.truthish"
compileSdk = 33
compileOptions {
// 1.8 is as low as we can go since kotlin can't target anything lower
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
fun shouldSign() = (findProperty("truthish.sign") as? String).toBoolean()
fun shouldPublishToGCloud(): Boolean {
return (findProperty("truthish.gcloud.publish") as? String).toBoolean()
&& findProperty("gcloud.artifact.registry.secret") != null
}
fun shouldPublishToMavenCentral(): Boolean {
return (findProperty("truthish.maven.publish") as? String).toBoolean()
&& findProperty("ossrhUsername") != null && findProperty("ossrhPassword") != null
}
val VARABYTE_REPO_URL = uri("https://us-central1-maven.pkg.dev/varabyte-repos/public")
fun MavenArtifactRepository.gcloudAuth() {
url = VARABYTE_REPO_URL
credentials {
username = "_json_key_base64"
password = findProperty("gcloud.artifact.registry.secret") as String
}
authentication {
create<BasicAuthentication>("basic")
}
}
val SONATYPE_RELEASE_REPO_URL = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
val SONATYPE_SNAPSHOT_REPO_URL = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
fun MavenArtifactRepository.sonatypeAuth() {
url = if (!version.toString().endsWith("SNAPSHOT")) SONATYPE_RELEASE_REPO_URL else SONATYPE_SNAPSHOT_REPO_URL
credentials {
username = findProperty("ossrhUsername") as String
password = findProperty("ossrhPassword") as String
}
authentication {
create<BasicAuthentication>("basic")
}
}
repositories {
mavenCentral()
}
val dokkaHtml by tasks.getting(DokkaTask::class)
val javadocJar: TaskProvider<Jar> by tasks.registering(Jar::class) {
dependsOn(dokkaHtml)
archiveClassifier.set("javadoc")
from(dokkaHtml.outputDirectory)
}
publishing {
publications {
if (shouldSign()) {
if (shouldPublishToGCloud()) {
repositories {
maven {
name = "GCloudMaven"
gcloudAuth()
}
}
}
if (shouldPublishToMavenCentral()) {
repositories {
maven {
name = "SonatypeMaven"
sonatypeAuth()
}
}
}
}
withType<MavenPublication> {
artifact(javadocJar)
pom {
val githubPath = "https://github.com/varabyte/truthish"
name.set("Truthish")
description.set("A Google Truth inspired testing library written in Kotlin supporting multi-platform projects")
url.set(githubPath)
scm {
url.set(githubPath)
val connectionPath = "scm:git:${githubPath}.git"
connection.set(connectionPath)
developerConnection.set(connectionPath)
}
developers {
developer {
id.set("bitspittle")
name.set("David Herman")
email.set("[email protected]")
}
}
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
}
}
}
}
if (shouldSign()) {
// If "shouldSign" returns true, then singing password should be set
val secretKeyRingExists = (findProperty("signing.secretKeyRingFile") as? String)
?.let { File(it).exists() }
?: false
// If "shouldSign" returns true, then singing password should be set
val signingPassword = findProperty("signing.password") as String
signing {
// If here, we're on a CI. Check for the signing key which must be set in an environment variable.
// See also: https://docs.gradle.org/current/userguide/signing_plugin.html#sec:in-memory-keys
if (!secretKeyRingExists) {
val signingKey: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
}
// Signing requires following steps at https://docs.gradle.org/current/userguide/signing_plugin.html#sec:signatory_credentials
// and adding singatory properties somewhere reachable, e.g. ~/.gradle/gradle.properties
sign(publishing.publications)
}
}
nexusPublishing {
repositories {
sonatype { //only for users registered in Sonatype after 24 Feb 2021
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
(findProperty("ossrhUsername") as? String)?.let { username.set(it) }
(findProperty("ossrhPassword") as? String)?.let { password.set(it) }
}
}
}