-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.gradle.kts
158 lines (138 loc) · 4.96 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
import java.util.Properties
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0")
}
}
val LIBRARY_VERSION_NAME = "0.7.0"
val GROUP_ID = "com.github.jershell"
val ARTIFACT_ID = rootProject.name
val BINTRAY_REPOSITORY = "generic"
val BINTRAY_ORGINIZATION = "jershell"
val KOTLINX_SERIALIZATION_RUNTIME = "1.6.3"
val SHORT_DESC = """
This adapter adds BSON support to kotlinx.serialization.
""".trimIndent()
val VCS_URL = "https://github.com/jershell/kbson.git"
val WEBSITE_URL = "https://github.com/jershell/kbson"
val ISSUE_TRACKER_URL = "https://github.com/jershell/kbson/issues"
val CONTACT_EMAIL = "[email protected]"
val properties = Properties().apply {
rootProject.file("local.properties").let { file ->
if (file.canRead()) {
load(file.reader())
}
}
}
repositories {
mavenCentral()
}
plugins {
kotlin("jvm") version "1.9.24" // or kotlin("multiplatform") or any other kotlin plugin
kotlin("plugin.serialization") version "1.9.24"
id("maven-publish")
signing
id("io.codearte.nexus-staging") version "0.30.0"
}
//apply(from = "io.codearte.nexus-staging")
group = GROUP_ID
version = LIBRARY_VERSION_NAME
dependencies {
// Use the Kotlin JDK 8 standard library.
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$KOTLINX_SERIALIZATION_RUNTIME")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$KOTLINX_SERIALIZATION_RUNTIME")
implementation("org.mongodb:bson:4.8.2")
// Use the Kotlin test library.
testImplementation("org.jetbrains.kotlin:kotlin-test")
// Use the Kotlin JUnit integration.
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
tasks.register<Jar>("sourcesAll") {
from(sourceSets.main.get().allSource)
archiveClassifier.set("sources")
}
tasks.withType<GenerateMavenPom>().configureEach {
val matcher = Regex("""generatePomFileFor(\w+)Publication""").matchEntire(name)
val publicationName = matcher?.let { it.groupValues[1] }
destination = file("$buildDir/poms/$publicationName-pom.xml")
}
tasks.register<Jar>("javadocJar") {
archiveClassifier.set("javadoc")
from("$rootDir/README.md")
}
fun printResults(desc: TestDescriptor, result: TestResult) {
if (desc.parent != null) {
val output = result.run {
"Results: $resultType (" +
"$testCount tests, " +
"$successfulTestCount successes, " +
"$failedTestCount failures, " +
"$skippedTestCount skipped" +
")"
}
val testResultLine = "| $output |"
val repeatLength = testResultLine.length
val seperationLine = "-".repeat(repeatLength)
println(seperationLine)
println(testResultLine)
println(seperationLine)
}
}
// publishing
publishing {
repositories {
val releasesUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
val snapshotsUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/")
maven {
name = "sonatypeSnapshotRepository"
url = if (version.toString().endsWith("SNAPSHOT")) snapshotsUrl else releasesUrl
credentials {
username = properties["mavencentral.username"] as String? ?: System.getenv("MVN_USERNAME")
password = properties["mavencentral.password"] as String? ?: System.getenv("MVN_PASSWORD")
}
}
}
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
artifact(tasks["sourcesAll"])
artifact(tasks["javadocJar"])
pom {
name.set(provider { "$GROUP_ID:$ARTIFACT_ID" })
description.set(provider { project.description ?: SHORT_DESC })
url.set(VCS_URL)
developers {
developer {
name.set(BINTRAY_ORGINIZATION)
email.set(CONTACT_EMAIL)
}
}
scm {
connection.set(VCS_URL)
developerConnection.set(VCS_URL)
url.set(ISSUE_TRACKER_URL)
}
licenses {
license {
name.set("MIT License")
url.set("http://www.opensource.org/licenses/mit-license.php")
}
}
}
}
}
}
signing {
useGpgCmd()
sign(publishing.publications["mavenJava"])
// sign(publishing.publications)
}
nexusStaging {
serverUrl = "https://oss.sonatype.org/service/local/"
username = properties["mavencentral.username"] as String? ?: System.getenv("MVN_USERNAME")
password = properties["mavencentral.password"] as String? ?: System.getenv("MVN_PASSWORD")
}