-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.gradle.kts
275 lines (251 loc) · 8.71 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// MIT License
//
// Copyright (c) 2022, Concordant and contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
// associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
// OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Gradle Build script
*
* Expected environment variables (may not be required):
* - OSSRH_USERNAME, OSSRH_TOKEN: MavenCentral credentials
* - NPMJS_AUTH_TOKEN: NPMjs credentials
* - CI_JOB_TOKEN: Gitlab CI job token (credentials for gitlab packages)
* - CI_PROJECT_ID: Gitlab Project ID, provided by CI (for gitlab packages)
*
* Expected Gradle properties (required by all Maven publishing tasks):
* - signing.secretKeyRingFile: path to GPG private signing key
* - signing.keyId: 8-characters GPG key ID
* - signing.password: GPG key password
*/
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
description = "The Concordant Conflict-Free Replicated Datatypes (CRDT) library"
group = "io.concordant"
version = "1.0.7"
plugins {
kotlin("multiplatform") version "1.4.10"
kotlin("plugin.serialization") version "1.4.10"
id("org.jetbrains.dokka") version "1.4.10.2"
id("maven-publish")
id("lt.petuska.npm.publish") version "1.1.1"
id("signing")
}
repositories {
jcenter()
mavenCentral()
maven(url = "https://jitpack.io") // necessary for ts-generator
}
configurations {
val ktlint by creating
}
dependencies {
"ktlint"("com.pinterest:ktlint:0.39.0")
}
// Kotlin build config, per target
kotlin {
// do not remove, even if empty
jvm() {
// uncomment if project contains Java source files
// withJava()
}
// Define "nodeJS" platform
js("nodeJs") {
// build for nodeJS
nodejs {}
}
// Dependencies, per source set
sourceSets {
all {
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
}
commonMain {
dependencies {
implementation(kotlin("reflect"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0")
}
}
commonTest {
dependencies {
implementation("io.kotest:kotest-property:4.3.1")
implementation("io.kotest:kotest-assertions-core:4.3.1")
}
}
val jvmMain by getting {
dependencies {
implementation("com.github.ntrrgc:ts-generator:1.1.1")
}
}
val jvmTest by getting {
dependencies {
implementation("io.kotest:kotest-runner-junit5-jvm:4.3.1")
}
}
val nodeJsTest by getting {
dependencies {
implementation("io.kotest:kotest-framework-engine:4.3.1")
}
}
}
tasks {
register<JavaExec>("tsgen") {
group = "build"
description = "Generate .d.ts description file"
dependsOn("compileKotlinJvm")
dependsOn("compileKotlinNodeJs")
val mainClasses = kotlin.targets["jvm"].compilations["main"]
classpath = configurations["jvmRuntimeClasspath"] + mainClasses.output.classesDirs
main = "crdtlib.GenerateTSKt"
outputs.file("$buildDir/js/packages/c-crdtlib-nodeJs/kotlin/c-crdtlib.d.ts")
}
register<Jar>("javadocJar") {
from(dokkaHtml)
archiveClassifier.set("javadoc")
}
register<JavaExec>("ktlint") {
group = "verification"
description = "Ktlint: check"
classpath = configurations["ktlint"]
main = "com.pinterest.ktlint.Main"
}
register<JavaExec>("ktlintFix") {
group = "verification"
description = "Ktlint: fix"
classpath = configurations["ktlint"]
main = "com.pinterest.ktlint.Main"
args("-F")
}
register<Copy>("installGitHook") {
group = "verification"
description = "Install Pre-commit linting hook"
from("pre-commit")
into(".git/hooks")
// Kotlin does not support octal litterals
fileMode = 7 * 64 + 7 * 8 + 7
}
}
}
tasks.withType<Test> {
useJUnitPlatform()
systemProperty("kotest.framework.timeout", 5000)
systemProperty("kotest.framework.invocation.timeout", 4000)
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
publishing {
publications {
withType<MavenPublication>().configureEach {
// MavenCentral requires javadoc and additional metadata
artifact(tasks.named("javadocJar"))
pom {
name.set("%s:%s".format(project.group, project.name))
description.set(project.description)
url.set("https://concordant.io")
licenses {
license {
name.set("MIT License")
url.set("https://www.opensource.org/licenses/mit-license.php")
}
}
developers {
developer {
name.set("Concordant")
email.set("[email protected]")
}
}
scm {
url.set("https://github.com/concordant/c-crdtlib")
}
}
}
}
repositories {
maven {
name = "Gitlab"
url = uri(
"https://gitlab.inria.fr/api/v4/projects/" +
"${System.getenv("CI_PROJECT_ID")}/packages/maven"
)
credentials(HttpHeaderCredentials::class) {
name = "Job-Token"
value = System.getenv("CI_JOB_TOKEN")
}
authentication {
create<HttpHeaderAuthentication>("header")
}
}
maven {
name = "MavenCentral"
url = uri(
"https://oss.sonatype.org/service/local/staging/deploy/maven2/"
)
credentials {
username = System.getenv("OSSRH_USERNAME")
password = System.getenv("OSSRH_TOKEN")
}
}
}
}
signing {
sign(publishing.publications)
// sign if signatory credentials are available only
setRequired(false)
// CI: use ASCII-armored key from environment variable
if ("GPG_SECRET_KEY" in System.getenv()) {
val signingKey = System.getenv("GPG_SECRET_KEY")
val signingKeyId = System.getenv("GPG_KEY_ID")
val signingPassword = System.getenv("GPG_PASSPHRASE")
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
}
}
npmPublishing {
// Maven uses reversed URLs as groupId, while NPM uses simple names
organization = "concordant"
readme = file("README.md")
repositories {
repository("Gitlab") {
access = RESTRICTED
registry = uri("https://gitlab.inria.fr/api/v4/projects/${System.getenv("CI_PROJECT_ID")}/packages/npm")
authToken = System.getenv("CI_JOB_TOKEN")
}
repository("npmjs") {
registry = uri("https://registry.npmjs.org")
authToken = System.getenv("NPMJS_AUTH_TOKEN")
}
}
publications {
val nodeJs by getting {
packageJson {
types = "c-crdtlib.d.ts"
"description" to project.description
keywords = mutableListOf("concordant", "crdt", "conflict-free", "replicated datatypes")
homepage = "concordant.io"
"license" to "MIT"
"bugs" to jsonObject {
"email" to "[email protected]"
}
}
}
}
}
// tasks dependencies
tasks {
named("nodeJsMainClasses") {
dependsOn("tsgen")
}
assemble {
dependsOn("installGitHook")
}
}