-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
224 lines (198 loc) · 7.66 KB
/
build.gradle.kts
File metadata and controls
224 lines (198 loc) · 7.66 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
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
plugins {
id("java")
id("jacoco")
id("signing")
id("maven-publish")
id("project-report")
id("com.diffplug.spotless") version "8.4.0"
id("com.github.ben-manes.versions") version "0.54.0"
id("io.freefair.lombok") version "9.4.0"
id("com.gradleup.nmcp").version("1.4.4")
kotlin("jvm") version "2.3.20"
}
group = "network.lightsail"
version = "3.0.0"
java {
toolchain {
// Tests and Kotlin compilation use JDK 21. The published SDK jar
// still targets JDK 8 bytecode via `options.release = 8` below.
languageVersion = JavaLanguageVersion.of(21)
}
}
kotlin {
jvmToolchain(21)
}
repositories {
mavenCentral()
}
spotless {
java {
importOrder("java", "javax", "org.stellar")
removeUnusedImports()
googleJavaFormat()
}
kotlin {
target("src/test/kotlin/**/*.kt")
ktfmt("0.56").googleStyle()
}
}
dependencies {
val okhttpVersion = "4.12.0"
implementation("com.squareup.okhttp3:okhttp:${okhttpVersion}")
implementation("com.squareup.okhttp3:okhttp-sse:${okhttpVersion}")
implementation("com.moandjiezana.toml:toml4j:0.7.2")
implementation("com.google.code.gson:gson:2.13.2")
implementation("org.bouncycastle:bcprov-jdk18on:1.84")
implementation("commons-codec:commons-codec:1.21.0")
testImplementation(kotlin("stdlib"))
testImplementation("org.mockito:mockito-core:5.23.0")
testImplementation("com.squareup.okhttp3:mockwebserver:${okhttpVersion}")
testImplementation("junit:junit:4.13.2")
testImplementation("org.bouncycastle:bcpkix-jdk18on:1.84") // mock https
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.11.3")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation("io.kotest:kotest-runner-junit5:6.1.11")
testImplementation("io.kotest:kotest-assertions-core:6.1.11")
}
tasks {
test {
useJUnitPlatform()
}
// Optional corpus verifier for SEP-0051/XDR-JSON. It is intentionally not wired into
// `test` or `check`; run it explicitly via `./gradlew verifyXdrJson --args='...'`.
register<JavaExec>("verifyXdrJson") {
group = "verification"
description = "Verifies generated XDR JSON against a corpus and the stellar CLI."
classpath = sourceSets.test.get().runtimeClasspath
mainClass.set("org.stellar.sdk.xdr.XdrJsonCorpusVerifier")
dependsOn(testClasses)
}
val sourcesJar by registering(Jar::class) {
archiveClassifier = "sources"
from(sourceSets.main.get().allSource)
}
val uberJar by registering(Jar::class) {
// https://docs.gradle.org/current/userguide/working_with_files.html#sec:creating_uber_jar_exampl
archiveClassifier = "uber"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from(sourceSets.main.get().output)
dependsOn(configurations.runtimeClasspath)
from({
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
})
exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA") // exclude signature files in org.bouncycastle:bcprov-jdk18on
}
javadoc {
setDestinationDir(file("javadoc"))
isFailOnError = false
options {
// https://docs.gradle.org/current/javadoc/org/gradle/external/javadoc/StandardJavadocDocletOptions.html
this as StandardJavadocDocletOptions
isSplitIndex = true
memberLevel = JavadocMemberLevel.PUBLIC
encoding = "UTF-8"
}
}
val javadocJar by registering(Jar::class) {
archiveClassifier = "javadoc"
dependsOn(javadoc)
from(javadoc.get().destinationDir) // It needs to be placed after the javadoc task, otherwise it cannot read the path we set.
}
register<Copy>("updateGitHook") {
from("scripts/pre-commit.sh") { rename { it.removeSuffix(".sh") } }
into(".git/hooks")
doLast {
file(".git/hooks/pre-commit").setExecutable(true)
}
}
jacocoTestReport {
dependsOn(compileJava, compileKotlin, processResources)
reports {
html.required = true
xml.required = true
}
classDirectories.setFrom(files(classDirectories.files.map {
fileTree(it) {
exclude("org/stellar/sdk/xdr/**")
}
}))
}
check {
dependsOn(jacocoTestReport)
}
assemble {
dependsOn(sourcesJar, uberJar, javadocJar)
}
compileJava {
options.encoding = "UTF-8"
options.release = 8
}
compileTestJava {
options.encoding = "UTF-8"
}
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
artifactId = "stellar-sdk"
from(components["java"])
artifact(tasks["uberJar"])
artifact(tasks["javadocJar"])
artifact(tasks["sourcesJar"])
pom {
name.set("stellar-sdk")
description.set("The Java Stellar SDK library provides APIs to build transactions and connect to Horizon and Soroban-RPC server.")
url.set("https://github.com/lightsail-network/java-stellar-sdk")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://github.com/lightsail-network/java-stellar-sdk/blob/master/LICENSE")
distribution.set("https://github.com/lightsail-network/java-stellar-sdk/blob/master/LICENSE")
}
}
developers {
developer {
id.set("overcat")
name.set("Jun Luo")
url.set("https://github.com/overcat")
}
organization {
name.set("Lightsail Network")
url.set("https://github.com/lightsail-network")
}
}
scm {
url.set("https://github.com/lightsail-network/java-stellar-sdk")
connection.set("scm:git:https://github.com/lightsail-network/java-stellar-sdk.git")
developerConnection.set("scm:git:ssh://git@github.com/lightsail-network/java-stellar-sdk.git")
}
}
}
}
}
signing {
val publishCommand = "publishAllPublicationsToCentralPortal"
isRequired = gradle.startParameter.taskNames.contains(publishCommand)
println("Need to sign? $isRequired")
// https://docs.gradle.org/current/userguide/signing_plugin.html#using_in_memory_ascii_armored_openpgp_subkeys
// export SIGNING_KEY=$(gpg2 --export-secret-keys --armor {SIGNING_KEY_ID} | grep -v '\-\-' | grep -v '^=.' | tr -d '\n')
val signingKey = System.getenv("SIGNING_KEY")
val signingKeyId = System.getenv("SIGNING_KEY_ID")
val signingPassword = System.getenv("SIGNING_PASSWORD")
if (isRequired && (signingKey == null || signingKeyId == null || signingPassword == null)) {
throw IllegalStateException("Please set the SIGNING_KEY, SIGNING_KEY_ID, and SIGNING_PASSWORD environment variables.")
}
println("Signing Key ID: $signingKeyId")
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
sign(publishing.publications["mavenJava"])
}
nmcp {
publishAllPublicationsToCentralPortal {
username = System.getenv("SONATYPE_USERNAME")
password = System.getenv("SONATYPE_PASSWORD")
// publish manually from the portal
publishingType = "USER_MANAGED"
// or if you want to publish automatically
// publishingType = "AUTOMATIC"
}
}