-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
84 lines (71 loc) · 2.33 KB
/
build.gradle.kts
File metadata and controls
84 lines (71 loc) · 2.33 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
import java.net.URI
plugins {
id("org.openapi.generator")
}
val jacksonVersion: String by project
// Authoritative source for the API spec
val apiSpecUrl = "https://developer.godaddy.com/swagger/swagger_ans.json"
val apiSpecFile = layout.buildDirectory.file("api-spec.json")
dependencies {
// Jackson for JSON serialization
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
// Jakarta annotations
implementation("jakarta.annotation:jakarta.annotation-api:3.0.0")
}
// Task to download the API spec from the authoritative source
val downloadApiSpec by tasks.registering {
val outputFile = apiSpecFile
outputs.file(outputFile)
doLast {
val destFile = outputFile.get().asFile
destFile.parentFile.mkdirs()
URI.create(apiSpecUrl).toURL().openStream().use { input ->
destFile.outputStream().use { output ->
input.copyTo(output)
}
}
logger.lifecycle("Downloaded API spec from $apiSpecUrl")
}
}
openApiGenerate {
generatorName.set("java")
inputSpec.set(apiSpecFile.get().asFile.absolutePath)
outputDir.set(layout.buildDirectory.dir("generated").get().asFile.absolutePath)
apiPackage.set("com.godaddy.ans.sdk.api.generated")
modelPackage.set("com.godaddy.ans.sdk.model.generated")
invokerPackage.set("com.godaddy.ans.sdk.client.generated")
configOptions.set(mapOf(
"library" to "native",
"dateLibrary" to "java8",
"useJakartaEe" to "true",
"openApiNullable" to "false",
"serializationLibrary" to "jackson",
"hideGenerationTimestamp" to "true"
))
}
sourceSets {
main {
java {
srcDir(layout.buildDirectory.dir("generated/src/main/java"))
}
}
}
tasks.openApiGenerate {
dependsOn(downloadApiSpec)
}
tasks.compileJava {
dependsOn(tasks.openApiGenerate)
}
// Disable checkstyle for generated code
tasks.named("checkstyleMain") {
enabled = false
}
// Ensure source/javadoc jars wait for code generation
tasks.named("sourcesJar") {
dependsOn(tasks.openApiGenerate)
}
tasks.named("javadocJar") {
dependsOn(tasks.openApiGenerate)
}