-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
166 lines (139 loc) · 5.79 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
159
160
161
162
163
164
165
166
import java.net.URL
plugins {
java
id("org.springframework.boot") version "3.1.5"
id("io.spring.dependency-management") version "1.1.3"
// Depedencies for Ebay hawk
id ("org.openapi.generator") version "7.0.1"
}
group = "io.irw"
version = "1.0-SNAPSHOT"
java {
sourceCompatibility = JavaVersion.VERSION_17
}
// Call it manually
//tasks.named("compileJava") {
// dependsOn("generateEbayApiClient")
//}
configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}
repositories {
mavenCentral()
}
extra["jacksonVersion"] = "2.15.3"
extra["swaggerVersion"] = "2.2.16"
extra["springBootAdminVersion"] = "3.1.7"
dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-logging")
implementation("de.codecentric:spring-boot-admin-starter-server")
implementation("io.micrometer:micrometer-tracing-bridge-brave")
implementation("io.zipkin.reporter2:zipkin-reporter-brave")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
// DB dependencies
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("io.hypersistence:hypersistence-utils-hibernate-62:3.6.1")
developmentOnly("org.springframework.boot:spring-boot-devtools")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.assertj:assertj-core:3.24.2")
implementation("org.liquibase:liquibase-core")
runtimeOnly("org.postgresql:postgresql")
implementation("org.projectlombok:lombok:1.18.30")
annotationProcessor("org.projectlombok:lombok")
implementation("org.mapstruct:mapstruct:1.5.5.Final")
// Mapstruct Processor (Annotation Processor)
annotationProcessor("org.mapstruct:mapstruct-processor:1.5.5.Final")
annotationProcessor("org.projectlombok:lombok-mapstruct-binding:0.2.0")
// Ebay hawk dependencies
// OpenAPI client dependencies
implementation("com.fasterxml.jackson.core:jackson-databind:${property("jacksonVersion")}")
implementation("com.fasterxml.jackson.module:jackson-modules-java8:${property("jacksonVersion")}")
implementation("io.swagger.core.v3:swagger-annotations:${property("swaggerVersion")}")
implementation("io.swagger.core.v3:swagger-models:${property("swaggerVersion")}")
implementation("org.openapitools:jackson-databind-nullable:0.2.6")
implementation("com.ebay.auth:ebay-oauth-java-client:1.1.8")
implementation("org.jgrapht:jgrapht-core:1.5.2")
}
dependencyManagement {
imports {
mavenBom("de.codecentric:spring-boot-admin-dependencies:${property("springBootAdminVersion")}")
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
sourceSets {
main {
java {
srcDir("src/main/java")
srcDir("${buildDir}/generated-sources/ebay-buy-browse-api/src/main/java")
srcDir("${buildDir}/generated-sources/ebay-feed-api/src/main/java")
}
}
}
data class ApiSpec(val apiArea: String, val apiName: String, val specUrl: String)
val ebayApiList = listOf(
ApiSpec("buy", "browse", "https://developer.ebay.com/api-docs/master/buy/browse/openapi/3/buy_browse_v1_oas3.yaml"),
ApiSpec("buy", "feed", "https://developer.ebay.com/api-docs/master/buy/feed/v1/openapi/3/buy_feed_v1_oas3.yaml"),
// Add more API specifications as needed
)
tasks.register("downloadEbaySpecs") {
doLast {
// Define the destination directory within the project
val destinationDir = layout.projectDirectory.dir("specs/ebay").asFile
// Create the destination directory if it doesn't exist
destinationDir.mkdirs()
// Iterate over the ebayApiList and download each specification
ebayApiList.forEach { apiSpec ->
val specFileName = "${apiSpec.apiArea}_${apiSpec.apiName}_v1_oas3.yaml"
val specFile = destinationDir.resolve(specFileName)
val specUrlObject = URL(apiSpec.specUrl)
specUrlObject.openStream().use { input ->
specFile.outputStream().use { output ->
input.copyTo(output)
}
}
}
println("${ebayApiList.size} eBay specifications downloaded to: $destinationDir")
}
}
// Define a function to generate tasks
fun createGenerateEbayClientTask(apiSpec: ApiSpec) {
tasks.register<org.openapitools.generator.gradle.plugin.tasks.GenerateTask>("generateEbay${apiSpec.apiArea.capitalize()}${apiSpec.apiName.capitalize()}ApiClient") {
generatorName.set("java")
library.set("resttemplate") // TODO: Wanted to use webclient, but https://stackoverflow.com/q/76730229/1421254
inputSpec.set("specs/ebay/${apiSpec.apiArea}_${apiSpec.apiName}_v1_oas3.yaml")
outputDir.set("${buildDir}/generated-sources/ebay-${apiSpec.apiArea}-${apiSpec.apiName}-api")
apiPackage.set("com.ebay.${apiSpec.apiArea}.${apiSpec.apiName}.api")
modelPackage.set("com.ebay.${apiSpec.apiArea}.${apiSpec.apiName}.model")
invokerPackage.set("com.ebay.${apiSpec.apiArea}.${apiSpec.apiName}.invoker")
configOptions.set(mapOf(
"dateLibrary" to "java8",
// needed because of https://stackoverflow.com/a/74996014
"useJakartaEe" to "true",
"generateClientAsBean" to "true",
"additionalModelTypeAnnotations" to "@lombok.Builder; @lombok.AllArgsConstructor",
// "webclientBlockingOperations" to "true"
))
generateApiTests.set(false)
generateModelTests.set(false)
}
}
// Create tasks using the list of ApiSpec objects
ebayApiList.forEach { apiSpec ->
createGenerateEbayClientTask(apiSpec)
}
// Define a task to generate all API clients
tasks.register("generateAllApiClients") {
dependsOn("downloadEbaySpecs")
finalizedBy(ebayApiList.map { apiSpec ->
tasks.named("generateEbay${apiSpec.apiArea.capitalize()}${apiSpec.apiName.capitalize()}ApiClient")
})
}