forked from Petersoj/alpaca-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
250 lines (206 loc) · 6.97 KB
/
build.gradle
File metadata and controls
250 lines (206 loc) · 6.97 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
249
250
import org.jsonschema2pojo.gradle.GenerateJsonSchemaJavaTask
buildscript {
repositories {
mavenCentral()
}
dependencies {
// For Maven and Maven Central support
classpath group: 'com.bmuschko', name: 'gradle-nexus-plugin', version: '2.3.1'
// For JSONSchema2POJO
classpath group: 'org.jsonschema2pojo', name: 'jsonschema2pojo-gradle-plugin', version: '1.1.1'
}
}
plugins {
id 'java'
// For Maven and Maven Central support
id 'maven-publish'
id 'com.bmuschko.nexus' version '2.3.1'
id 'io.codearte.nexus-staging' version '0.11.0'
// For code coverage reports
id 'jacoco'
}
apply plugin: 'jsonschema2pojo'
archivesBaseName = 'alpaca-java'
group = 'net.jacobpeterson'
version = '9.1.2-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
// Logging framework
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.36'
// This is a bridge for the Apache Jakarta Commons Logging library used in dependencies to actually use SLF4j instead
implementation group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.36'
// Guava and GSON
implementation group: 'com.google.guava', name: 'guava', version: '31.1-jre'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.9.0'
// OkHttp
implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.10.0'
implementation group: 'com.github.devcsrj', name: 'slf4j-okhttp3-logging-interceptor', version: '1.0.1'
// Unit test dependencies
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.36'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.8.2'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.6.1'
}
// Exclude any SLF4j-implementation transitive dependencies so users can use a logging framework of their choice
configurations.implementation {
exclude group: 'commons-logging', module: 'commons-logging'
}
sourceSets {
main {
java {
srcDirs 'src/main/java'
}
}
test {
java {
srcDirs 'src/test/java'
}
}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
javadoc {
// Explicitly define source version
options.addStringOption('source', '8')
// Used to suppress Javadoc linting warnings
options.addStringOption('Xdoclint:none', '-quiet')
// Explicitly define Charset for Javadocs
options.addStringOption('charset', 'UTF-8')
// Add Java SE 8 link
options.addStringOption('link', 'https://docs.oracle.com/javase/8/docs/api/')
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
}
doFirst {
def testPackageArgument = "testPackage"
filter.includeTestsMatching(project.hasProperty(testPackageArgument) &&
project.getProperty(testPackageArgument).equals("live") ? "*.live.*" : "*.mock.*")
}
}
jacocoTestReport {
reports {
xml.enabled true
html.enabled false
}
}
jacocoTestReport.dependsOn check
//
// START publishing
//
modifyPom {
project {
name = 'alpaca-java'
description = 'Java API for Alpaca'
url = 'https://github.com/Petersoj/alpaca-java'
inceptionYear = '2018'
licenses {
license {
name = 'MIT License'
url = 'https://opensource.org/licenses/MIT'
}
}
developers {
developer {
id = 'Petersoj'
name = 'Jacob Peterson'
}
developer {
id = 'mainstringargs'
name = 'main(String[] args)'
}
}
scm {
url = "https://github.com/Petersoj/alpaca-java.git"
connection = "scm:git:https://github.com/Petersoj/alpaca-java.git"
developerConnection = "scm:git:git@github.com/Petersoj/alpaca-java.git"
}
}
}
extraArchive {
sources = true
tests = true
javadoc = true
}
nexus {
sign = true
repositoryUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
snapshotRepositoryUrl = 'https://oss.sonatype.org/content/repositories/snapshots/'
}
nexusStaging {
packageGroup = "net.jacobpeterson"
}
// Used to prevent accidental publication of Alpaca keys
processResources {
exclude('alpaca.properties')
}
//
// END publishing
//
//
// START POJO generation
//
// Disable default 'jsonSchema2Pojo' task
tasks.getByName("generateJsonSchema2Pojo").enabled(false)
// The generated POJOs will be in a package structure analogous to the path in the 'schema_json/' directory
// See: https://github.com/joelittlejohn/jsonschema2pojo/wiki/Reference
final def targetDirectoryPath = file("${project.buildDir}/generated-sources/schemajson").getPath()
task generatePOJOs() {
final def jsonSourceDirectory = file("${project.projectDir}/schema_json").getPath()
final def jsonPackageNamePrefix = "net.jacobpeterson.alpaca.model"
// Loop through all files in schema JSON file tree
file(jsonSourceDirectory).eachFileRecurse { jsonFile ->
if (jsonFile.getName().endsWith(".json")) {
def startPackageIndex = jsonFile.getAbsolutePath().indexOf(jsonSourceDirectory) + jsonSourceDirectory.length()
def targetPackage = jsonPackageNamePrefix + jsonFile.getParentFile().getAbsolutePath()
.substring(startPackageIndex)
.replace(File.separator, '.').replace('-', '').replace('_', '')
.toLowerCase()
def jsonToPOJOTask = tasks.create('json2POJOTask-' + targetPackage + "." + jsonFile.getName(),
GenerateJsonSchemaJavaTask)
// Configure this task to participate in incremental builds so that it only executes when changes occur
jsonToPOJOTask.configure {
inputs.file(jsonFile)
outputs.dir(targetDirectoryPath)
}
jsonToPOJOTask.doFirst {
jsonToPOJOTask.configuration.source = files(jsonFile.getAbsolutePath())
jsonToPOJOTask.configuration.targetDirectory = file(targetDirectoryPath)
jsonToPOJOTask.configuration.targetPackage = targetPackage
}
dependsOn jsonToPOJOTask
}
}
}
compileJava {
dependsOn generatePOJOs
}
sourceSets {
main {
java {
srcDir targetDirectoryPath
}
}
}
jsonSchema2Pojo {
includeAdditionalProperties = true
targetDirectory = file(targetDirectoryPath)
propertyWordDelimiters = ['-', '_'] as char[]
annotationStyle = 'gson'
sourceType = 'jsonschema'
customDateTimePattern = "yyyy-MM-ddTHH:mm:ssZ"
includeConstructors = true
serializable = true
includeGetters = true
includeSetters = true
includeCopyConstructor = true
generateBuilders = true
}
//
// END POJO generation
//