-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
254 lines (217 loc) · 7.43 KB
/
build.gradle
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
249
250
251
252
253
254
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('io.swagger.codegen.v3:swagger-codegen:3.0.52')
classpath('com.github.jengelman.gradle.plugins:shadow:2.0.2')
classpath('io.swagger.codegen.v3:swagger-codegen-generators:1.0.46')
}
}
plugins {
id 'idea'
id 'java-library'
id 'maven-publish'
id 'signing'
id 'org.ajoberstar.grgit' version '2.2.1'
}
import org.ajoberstar.grgit.Grgit
apply from: 'versioning.gradle'
group = applicationGroupId
def codegenJavaDir = "$project.rootDir/generated"
def codegenPythonDir = "$project.rootDir/generated-python"
def codegenJavaSrcDir = codegenJavaDir + "/src/main/java"
def codegenJavaResourceDir = codegenJavaDir + "/src/main/resources"
configurations {
all {
resolutionStrategy {
cacheDynamicVersionsFor 0, 'seconds'
}
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "log4j", module: "log4j"
exclude group: "org.eclipse.jetty", module: "jetty-server"
}
swaggerCodegen
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
swaggerCodegen 'io.swagger.codegen.v3:swagger-codegen:3.0.52'
implementation 'io.swagger.core.v3:swagger-annotations:2.2.20'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
implementation 'com.squareup.okhttp:logging-interceptor:2.7.5'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.16.1'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'joda-time:joda-time:2.12.6'
implementation 'io.gsonfire:gson-fire:1.9.0'
implementation 'javax.annotation:javax.annotation-api:1.3.2'
testImplementation 'junit:junit:4.13.1'
}
ext {
startTime = new Date().format("yyy-MM-dd'T'HH:mm:ssZ")
def gitRepo = Grgit.open(dir: projectDir.toString())
def gitHash = gitRepo.head().id
def gitBranch = gitRepo.branch.current().name
def gitBranchFullName = gitRepo.branch.current().fullName
gitRepo.close()
currentJvm = Jvm.current()
if (gitBranch.startsWith('refs/heads/release')) { // also set in
project.version = getReleaseVersion()
println 'Building release: ' + project.version
artifactoryRepo = 'libs-snapshot-local'
} else if (gitBranch == 'dev') {
println 'Building dev branch'
project.version = getDevVersion(null)
artifactoryRepo = 'libs-snapshot-local'
} else {
def branchVersionIdentifier = gitBranch.replaceAll("\\W", "_")
println 'Building branch: ' + branchVersionIdentifier
project.version = getDevVersion(branchVersionIdentifier)
artifactoryRepo = 'libs-snapshot-local'
}
println 'Branch Ref: ' + gitBranchFullName + ' (' + gitHash + ')'
println 'Version: ' + project.version
}
sourceSets {
main {
java {
srcDirs = [codegenJavaSrcDir]
}
resources {
srcDirs = [codegenJavaResourceDir]
}
}
}
java {
withJavadocJar()
withSourcesJar()
}
compileJava {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
jar {
manifest {
attributes(
'Implementation-Title': project.applicationTitle,
'Implementation-Version': project.version
)
}
}
tasks.named("sourcesJar") {
mustRunAfter(":generateJavaClient")
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
version project.version
pom.withXml {
asNode().children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
name project.applicationTitle
description project.applicationDescription
url project.url
scm {
url project.url
connection project.scmUrl
developerConnection project.scmUrl
}
licenses {
license {
name project.licenseName
url project.licenseUrl
distribution 'repo'
}
}
}
}
}
}
repositories {
maven {
url = System.getenv('URL') + '/artifactory/' + artifactoryRepo
credentials(HttpHeaderCredentials) {
name = "X-JFrog-Art-API"
value = System.getenv('TOKEN')
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
import io.swagger.codegen.v3.DefaultGenerator
import io.swagger.codegen.v3.CodegenConfigLoader
import io.swagger.codegen.v3.ClientOptInput
import io.swagger.codegen.v3.ClientOpts
import io.swagger.v3.parser.OpenAPIV3Parser
import org.gradle.internal.jvm.Jvm
tasks.register('generateJavaClient') {
FileTree swaggerFiles = fileTree('.') {
include 'swagger.yaml'
}
inputs.files(swaggerFiles)
outputs.dir(codegenJavaDir)
doLast {
swaggerFiles.each { File file ->
println "Java Client Generator: processing file - " + file
def codegenConfig = CodegenConfigLoader.forName('java')
codegenConfig.setOutputDir(codegenJavaDir)
codegenConfig.setLibrary('okhttp-gson')
def options = new ClientOpts()
options.setProperties([
'dateLibrary' : 'java8',
'apiPackage' : 'com.elyxor.cachethq.api',
'modelPackage' : 'com.elyxor.cachethq.model',
'sourceFolder' : 'src/main/java',
'interfaceOnly': 'true'
])
def openAPI = new OpenAPIV3Parser().read(file.toString(), null, null)
def clientOpts = new ClientOptInput()
clientOpts.setOpenAPI(openAPI)
clientOpts.setConfig(codegenConfig)
clientOpts.setOpts(options)
new DefaultGenerator().opts(clientOpts).generate()
}
}
}
tasks.register('generatePythonClient') {
FileTree swaggerFiles = fileTree('.') {
include 'swagger.yaml'
}
inputs.files(swaggerFiles)
outputs.dir(codegenPythonDir)
doLast {
swaggerFiles.each { File file ->
println "Python Client Generator: processing file - " + file
def codegenConfig = CodegenConfigLoader.forName('python')
codegenConfig.setOutputDir(codegenPythonDir)
def options = new ClientOpts()
options.setProperties([
'packageName': 'cachethq_client',
'projectName': 'cachethq-client',
])
def openAPI = new OpenAPIV3Parser().read(file.toString(), null, null)
def clientOpts = new ClientOptInput()
clientOpts.setOpenAPI(openAPI)
clientOpts.setConfig(codegenConfig)
clientOpts.setOpts(options)
new DefaultGenerator().opts(clientOpts).generate()
}
}
}
tasks.register('copyPyProjectFile', Copy) {
from "${rootProject.projectDir}/pyproject.toml"
from "${rootProject.projectDir}/PYPI-README.md"
into(codegenPythonDir)
}
compileJava.dependsOn generateJavaClient
compileJava.dependsOn generatePythonClient
tasks.generatePythonClient.finalizedBy copyPyProjectFile
clean.doFirst {
delete(codegenJavaDir)
delete(codegenPythonDir)
}