-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
232 lines (206 loc) · 8.13 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
232 lines (206 loc) · 8.13 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
225
226
227
228
229
230
231
232
plugins {
`java-library`
jacoco
alias(libs.plugins.spotless)
alias(libs.plugins.vanniktech.publish)
}
// Maven groupId = the verified Central Portal namespace (domain marketdata.app,
// reversed). Independent of the Java package, which stays com.marketdata.sdk.
group = "app.marketdata"
// Version is overridable from the command line so a manual Central Portal
// validation run can use a real release version (e.g. `-PsdkVersion=1.0.0`)
// without committing it. Default stays on the in-development SNAPSHOT.
version = (findProperty("sdkVersion") as String?) ?: "1.0.0-SNAPSHOT"
// ADR-002: minimum JDK 17, build with --release 17, single bytecode level.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
// Sources/Javadoc jars are produced by the Vanniktech publish plugin
// (see mavenPublishing block below). Duplicating them via
// withJavadocJar()/withSourcesJar() here causes "multiple artifacts
// with classifier 'javadoc'" failures at publish time.
}
tasks.withType<JavaCompile>().configureEach {
options.release = 17
options.encoding = "UTF-8"
options.compilerArgs.add("-Xlint:all")
}
tasks.withType<Javadoc>().configureEach {
options.encoding = "UTF-8"
}
// SDK requirements §15: version must be auto-detected from package
// metadata. Internal Version.current() reads this attribute at runtime.
tasks.jar {
manifest {
attributes(
"Implementation-Title" to "marketdata-sdk-java",
"Implementation-Version" to project.version,
)
}
}
// ADR-003: integration tests live in a separate, env-var-gated source set.
val integrationTest by sourceSets.creating {
// Wire the main and unit-test outputs into the integration test classpath
// so ITs can use both production code and test helpers (junit, assertj).
compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output
runtimeClasspath += output + compileClasspath
}
val integrationTestImplementation by configurations.getting {
extendsFrom(configurations.testImplementation.get())
}
val integrationTestRuntimeOnly by configurations.getting {
extendsFrom(configurations.testRuntimeOnly.get())
}
val integrationTestTask = tasks.register<Test>("integrationTest") {
description = "Runs integration tests against the live Market Data API."
group = "verification"
testClassesDirs = integrationTest.output.classesDirs
classpath = integrationTest.runtimeClasspath
useJUnitPlatform()
onlyIf {
System.getenv("MARKETDATA_RUN_INTEGRATION_TESTS") == "true"
}
shouldRunAfter(tasks.test)
}
tasks.check { dependsOn(integrationTestTask) }
dependencies {
// ADR-001 §2.1: JSpecify nullability annotations are compile-time only.
// compileOnlyApi makes them visible to consumers' compilers without a runtime dep.
compileOnlyApi(libs.jspecify)
// ADR-005: Jackson is the JSON library. Implementation (not api) since
// consumers see typed records, not Jackson types directly.
implementation(libs.jackson.databind)
testImplementation(libs.junit.jupiter)
testImplementation(libs.assertj.core)
testRuntimeOnly(libs.junit.platform.launcher)
}
tasks.test {
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport)
}
// ADR-002 CI matrix: optionally run any Test task on a specific JDK
// while compilation stays pinned to --release 17. The flag is wired to
// every Test task (unit `test` + `integrationTest`) so on-demand and
// merge-to-main matrix runs cover the live API on JDK 17/21/25 too.
val testJdkProperty = providers.gradleProperty("testJdk").orNull
if (testJdkProperty != null) {
val launcher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(testJdkProperty.toInt())
}
tasks.withType<Test>().configureEach {
javaLauncher.set(launcher)
}
}
tasks.jacocoTestReport {
dependsOn(tasks.test)
reports {
xml.required = true
html.required = true
}
}
// Aggregate coverage across unit tests and integration tests. Opt-in: not
// wired into `check` so PR builds stay fast and don't require the IT secret.
// Invoke as `MARKETDATA_RUN_INTEGRATION_TESTS=true ./gradlew jacocoAggregateReport`.
tasks.register<JacocoReport>("jacocoAggregateReport") {
description = "Generates a JaCoCo report aggregating unit + integration test coverage."
group = "verification"
dependsOn(tasks.test, integrationTestTask)
sourceSets(sourceSets.main.get())
executionData(
fileTree(layout.buildDirectory.dir("jacoco")) {
include("*.exec")
},
)
reports {
xml.required = true
html.required = true
html.outputLocation = layout.buildDirectory.dir("reports/jacoco/aggregate/html")
xml.outputLocation = layout.buildDirectory.file("reports/jacoco/aggregate/jacoco.xml")
}
}
// Coverage ratchet (line coverage cannot drop more than 5 pp below main's last value) is enforced
// in CI — see .github/workflows/pull-request.yml and .github/scripts/check-coverage-delta.py.
//
// SDK requirements §15.3: 100% line coverage. Enforced locally and in CI by
// jacocoTestCoverageVerification (wired into `check`). The handful of genuinely untestable lines —
// network-only constructor paths, fail-safe catch blocks, TOCTOU retry edges — are isolated into
// members annotated @Generated, which JaCoCo excludes from the count (the annotation's simple name
// contains "Generated", the marker JaCoCo recognizes since 0.8.2). Each use carries a comment
// explaining why the member is unreachable from a hermetic unit test.
tasks.jacocoTestCoverageVerification {
dependsOn(tasks.test)
violationRules {
rule {
limit {
counter = "LINE"
value = "COVEREDRATIO"
minimum = "1.0".toBigDecimal()
}
}
}
}
tasks.named("check") {
dependsOn(tasks.jacocoTestCoverageVerification)
}
spotless {
java {
target("src/**/*.java")
googleJavaFormat()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
kotlinGradle {
target("*.gradle.kts", "**/*.gradle.kts")
}
}
// ADR-003 / requirements §15: Maven Central publishing via Vanniktech.
//
// Publishes to the Sonatype Central Portal (central.sonatype.com).
// `automaticRelease = false` uploads the deployment but leaves it in the
// VALIDATED state for manual review/release (or drop) from the portal UI —
// the safe path for a first manual validation run.
//
// Upload + signing credentials are read from Gradle properties / env vars by
// the plugin (never hard-coded here):
// - ORG_GRADLE_PROJECT_mavenCentralUsername / _mavenCentralPassword
// - ORG_GRADLE_PROJECT_signingInMemoryKey / _signingInMemoryKeyPassword
// (optionally _signingInMemoryKeyId)
mavenPublishing {
publishToMavenCentral(automaticRelease = false)
signAllPublications()
coordinates(group.toString(), "marketdata-sdk-java", version.toString())
pom {
name.set("Market Data Java & Kotlin SDK")
description.set(
"Official Java & Kotlin SDK for the Market Data API — real-time and " +
"historical financial data: stocks, options, mutual funds, and market status."
)
url.set("https://www.marketdata.app/docs/sdk/java")
inceptionYear.set("2026")
licenses {
license {
name.set("MIT License")
url.set("https://github.com/MarketDataApp/sdk-java/blob/main/LICENSE")
distribution.set("repo")
}
}
developers {
developer {
id.set("marketdata")
name.set("Market Data")
url.set("https://www.marketdata.app")
}
}
scm {
url.set("https://github.com/MarketDataApp/sdk-java")
connection.set("scm:git:git://github.com/MarketDataApp/sdk-java.git")
developerConnection.set("scm:git:ssh://git@github.com/MarketDataApp/sdk-java.git")
}
issueManagement {
system.set("GitHub")
url.set("https://github.com/MarketDataApp/sdk-java/issues")
}
}
}