-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
248 lines (210 loc) · 8.93 KB
/
build.gradle.kts
File metadata and controls
248 lines (210 loc) · 8.93 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.testing.TestDescriptor
import org.gradle.api.tasks.testing.TestListener
import org.gradle.api.tasks.testing.TestResult
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.external.javadoc.StandardJavadocDocletOptions
import org.gradle.jvm.toolchain.JavaToolchainService
import java.util.Properties
import java.io.FileInputStream
plugins {
`java-library`
`maven-publish`
signing
id("com.gradleup.nmcp") version "1.4.3"
id("com.diffplug.spotless") version "6.25.0"
}
// Load .env file if it exists
val envFile = file(".env")
if (envFile.exists()) {
val props = Properties()
FileInputStream(envFile).use { props.load(it) }
props.forEach { key, value ->
var strValue = value.toString().trim()
if (strValue.startsWith("\"") && strValue.endsWith("\"") && strValue.length >= 2) {
strValue = strValue.substring(1, strValue.length - 1)
} else if (strValue.startsWith("'") && strValue.endsWith("'") && strValue.length >= 2) {
strValue = strValue.substring(1, strValue.length - 1)
}
// Remove 'APPLE_MAPS_TOKEN=' prefix if mistakenly included in the value
if (strValue.startsWith("APPLE_MAPS_TOKEN=")) {
strValue = strValue.substring("APPLE_MAPS_TOKEN=".length)
}
System.setProperty(key.toString(), strValue)
}
}
val javaTargetVersion = 17
group = providers.gradleProperty("GROUP").orNull ?: "com.williamcallahan"
version = providers.gradleProperty("version").orNull
?: providers.gradleProperty("VERSION_NAME").orNull
?: "0.1.5"
repositories {
mavenCentral()
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(javaTargetVersion))
}
withSourcesJar()
withJavadocJar()
}
val javaToolchainService = extensions.getByType<JavaToolchainService>()
val javaLauncherForTargetVersion = javaToolchainService.launcherFor {
languageVersion.set(JavaLanguageVersion.of(javaTargetVersion))
}
dependencies {
implementation(platform("tools.jackson:jackson-bom:3.0.4"))
implementation("tools.jackson.core:jackson-databind")
implementation("com.fasterxml.jackson.core:jackson-annotations")
testImplementation("org.junit.jupiter:junit-jupiter:6.0.2")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:6.0.2")
}
spotless {
java {
target("src/**/*.java")
trimTrailingWhitespace()
endWithNewline()
}
format("misc") {
target("*.gradle.kts", "*.md", ".gitignore", "Makefile")
trimTrailingWhitespace()
endWithNewline()
}
}
tasks.withType<JavaCompile>().configureEach {
options.release.set(javaTargetVersion)
options.compilerArgs.add("-Xlint:unchecked")
options.compilerArgs.add("-Xlint:deprecation")
}
val integrationTestPattern = "*IT"
tasks.withType<Test>().configureEach {
useJUnitPlatform()
javaLauncher.set(javaLauncherForTargetVersion)
// Pass APPLE_MAPS_TOKEN to tests
val token = System.getenv("APPLE_MAPS_TOKEN") ?: System.getProperty("APPLE_MAPS_TOKEN")
if (token != null) {
environment("APPLE_MAPS_TOKEN", token)
}
}
tasks.register<Test>("testDetail") {
description = "Runs integration tests with detailed logging."
group = "verification"
val testSourceSet = sourceSets["test"]
testClassesDirs = testSourceSet.output.classesDirs
classpath = testSourceSet.runtimeClasspath
filter {
includeTestsMatching(integrationTestPattern)
}
testLogging {
events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = true
}
addTestListener(object : TestListener {
override fun beforeSuite(suite: TestDescriptor) = Unit
override fun beforeTest(testDescriptor: TestDescriptor) = Unit
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {
val testClassName = testDescriptor.className ?: testDescriptor.name
logger.lifecycle("TEST ${result.resultType}: ${testClassName}.${testDescriptor.name}")
}
override fun afterSuite(suite: TestDescriptor, result: TestResult) {
if (suite.parent == null) {
logger.lifecycle(
"TEST SUMMARY: ${result.resultType} (" +
"${result.testCount} tests, " +
"${result.successfulTestCount} passed, " +
"${result.failedTestCount} failed, " +
"${result.skippedTestCount} skipped)"
)
}
}
})
}
tasks.withType<JavaExec>().configureEach {
javaLauncher.set(javaLauncherForTargetVersion)
}
tasks.named("check") {
dependsOn("spotlessCheck")
}
tasks.register<JavaExec>("cli") {
description = "Runs the Apple Maps CLI against the live API."
group = "application"
classpath = sourceSets["main"].runtimeClasspath
mainClass.set("com.williamcallahan.applemaps.cli.AppleMapsCli")
val token = System.getenv("APPLE_MAPS_TOKEN") ?: System.getProperty("APPLE_MAPS_TOKEN")
if (token != null) {
environment("APPLE_MAPS_TOKEN", token)
}
val userLocation = System.getenv("APPLE_MAPS_USER_LOCATION") ?: System.getProperty("APPLE_MAPS_USER_LOCATION")
if (userLocation != null) {
environment("APPLE_MAPS_USER_LOCATION", userLocation)
}
val userLocationQuery = System.getenv("APPLE_MAPS_USER_LOCATION_QUERY") ?: System.getProperty("APPLE_MAPS_USER_LOCATION_QUERY")
if (userLocationQuery != null) {
environment("APPLE_MAPS_USER_LOCATION_QUERY", userLocationQuery)
}
}
tasks.withType<Javadoc>().configureEach {
(options as StandardJavadocDocletOptions).addStringOption("-release", javaTargetVersion.toString())
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
artifactId = providers.gradleProperty("POM_ARTIFACT_ID").orNull ?: "apple-maps-java"
pom {
name.set(providers.gradleProperty("POM_NAME").orNull ?: "Apple Maps Java")
description.set(providers.gradleProperty("POM_DESCRIPTION").orNull ?: "Apple Maps Java implements the Apple Maps Server API for use in JVMs.")
url.set(providers.gradleProperty("POM_URL").orNull ?: "https://github.com/WilliamAGH/apple-maps-java")
licenses {
license {
name.set(providers.gradleProperty("POM_LICENSE_NAME").orNull ?: "MIT License")
url.set(providers.gradleProperty("POM_LICENSE_URL").orNull ?: "https://opensource.org/license/mit")
}
}
developers {
developer {
id.set(providers.gradleProperty("POM_DEVELOPER_ID").orNull ?: "WilliamAGH")
name.set(providers.gradleProperty("POM_DEVELOPER_NAME").orNull ?: "William Callahan")
url.set(providers.gradleProperty("POM_DEVELOPER_URL").orNull ?: "https://github.com/WilliamAGH/")
}
}
scm {
url.set(providers.gradleProperty("POM_SCM_URL").orNull ?: "https://github.com/WilliamAGH/apple-maps-java")
connection.set(providers.gradleProperty("POM_SCM_CONNECTION").orNull ?: "scm:git:git://github.com/WilliamAGH/apple-maps-java.git")
developerConnection.set(providers.gradleProperty("POM_SCM_DEV_CONNECTION").orNull ?: "scm:git:ssh://git@github.com/WilliamAGH/apple-maps-java.git")
}
}
}
}
repositories {
maven {
val releasesUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
val snapshotsUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
url = if (version.toString().endsWith("SNAPSHOT")) snapshotsUrl else releasesUrl
credentials {
username = providers.environmentVariable("SONATYPE_USERNAME").orNull
password = providers.environmentVariable("SONATYPE_PASSWORD").orNull
}
}
}
}
signing {
val signingKey = providers.environmentVariable("GPG_PRIVATE_KEY").orNull
val signingPassword = providers.environmentVariable("GPG_PASSPHRASE").orNull
if (signingKey != null && signingPassword != null) {
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}
}
nmcp {
publishAllPublicationsToCentralPortal {
username.set(providers.environmentVariable("SONATYPE_USERNAME").orNull)
password.set(providers.environmentVariable("SONATYPE_PASSWORD").orNull)
publishingType.set("USER_MANAGED")
}
}