-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.gradle
210 lines (179 loc) · 6.56 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
import org.jsonschema2pojo.gradle.GenerateJsonSchemaJavaTask
buildscript {
repositories {
mavenCentral()
}
dependencies {
// For JSONSchema2POJO
classpath group: 'org.jsonschema2pojo', name: 'jsonschema2pojo-gradle-plugin', version: 'latest.integration'
}
}
plugins {
id "java"
id "java-library"
// For Maven Central publishing
id "maven-publish"
id "signing"
}
// 'apply' here instead of in plugins closure because 'jsonschema2pojo' doesn't exist in the
// Gradle Central Plugin Repository (it's only in Maven central).
apply plugin: 'jsonschema2pojo'
final def projectGroup = "net.jacobpeterson"
final def projectArtifactID = "iqfeed4j"
final def projectVersion = "6.2-2.0.0-SNAPSHOT"
group = projectGroup
version = projectVersion
repositories {
mavenCentral()
}
dependencies {
// Logging framework
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.36'
// Google Guava for a variety of useful methods
implementation group: 'com.google.guava', name: 'guava', version: '31.1-jre'
// Jackson for XML <-> POJO (de)serialization
// Note: not using JAXB since it's slower and Jackson XML has more features
implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: '2.13.3'
implementation group: 'org.codehaus.woodstox', name: 'woodstox-core-asl', version: '4.4.1'
// For JDK 8 common Jackson (de)serializers
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.13.3'
// Apache Commons object pooling
implementation group: 'org.apache.commons', name: 'commons-pool2', version: '2.11.1'
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withJavadocJar()
withSourcesJar()
}
[compileJava, compileTestJava]*.options*.encoding = "UTF-8"
javadoc {
options.addStringOption("source", "17")
options.addStringOption("charset", "UTF-8")
options.addStringOption("Xdoclint:none", "-quiet") // Suppress Javadoc linting warnings
options.addStringOption("link", "https://docs.oracle.com/en/java/javase/17/docs/api/")
}
//
// BEGIN Publishing
//
publishing {
publications {
mavenJava(MavenPublication) {
groupId = projectGroup
artifactId = projectArtifactID
version = projectVersion
from(components["java"])
pom {
name = projectArtifactID
description = "A Java API for the market data vendor DTN IQFeed."
url = "https://github.com/Petersoj/IQFeed4j"
inceptionYear = "2021"
licenses {
license {
name = "MIT License"
url = "https://opensource.org/licenses/MIT"
}
}
developers {
developer {
id = "Petersoj"
name = "Jacob Peterson"
}
}
scm {
url = "https://github.com/Petersoj/IQFeed4j.git"
connection = "scm:git:https://github.com/Petersoj/IQFeed4j.git"
developerConnection = "scm:git:[email protected]/Petersoj/IQFeed4j.git"
}
}
}
}
repositories {
maven {
name = "OSSRH"
url = projectVersion.contains("SNAPSHOT") ? "https://oss.sonatype.org/content/repositories/snapshots/" :
"https://oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username = project.property("nexus.username")
password = project.property("nexus.password")
}
}
}
}
signing {
sign publishing.publications.mavenJava
}
//
// 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 jsonPackageNameStart = 'net.jacobpeterson.iqfeed4j.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 = jsonPackageNameStart + 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 = false
targetDirectory = file(targetDirectoryPath)
propertyWordDelimiters = ['-', '_'] as char[]
annotationStyle = 'none'
sourceType = 'jsonschema'
customDateTimePattern = 'yyyy-MM-ddTHH:mm:ssZ'
includeConstructors = true
serializable = true
includeGetters = true
includeSetters = true
}
javadocJar.dependsOn generatePOJOs
sourcesJar.dependsOn generatePOJOs
jar.dependsOn compileJava
javadocJar.dependsOn compileJava
sourcesJar.dependsOn compileJava
tasks.jar {
manifest {
attributes(Map.of("Automatic-Module-Name", "$projectGroup.$projectArtifactID"))
}
}
//
// END POJO generation
//