-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathbuild.gradle
More file actions
417 lines (372 loc) · 14.3 KB
/
Copy pathbuild.gradle
File metadata and controls
417 lines (372 loc) · 14.3 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath 'ru.vyarus:gradle-quality-plugin:6.1.0'
classpath 'pl.allegro.tech.build:axion-release-plugin:1.18.18'
classpath 'io.github.gradle-nexus:publish-plugin:2.0.0'
classpath 'com.diffplug.spotless:spotless-plugin-gradle:7.0.3'
}
}
apply plugin: 'pl.allegro.tech.build.axion-release'
apply plugin: 'java-library-distribution'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'jacoco'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'ru.vyarus.quality'
apply plugin: 'io.github.gradle-nexus.publish-plugin'
archivesBaseName = 'pw-swift-core'
group 'com.prowidesoftware'
project.ext {
SRU = 'SRU2025'
}
scmVersion {
versionCreator('simple')
tag {
prefix = SRU
versionSeparator = '-'
}
}
project.version = "${SRU}-${scmVersion.version}"
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
doFirst {
println 'Compiling with ' + getJavaCompiler().get().getMetadata().getInstallationPath()
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.apache.commons:commons-lang3:3.20.0'
implementation 'org.apache.commons:commons-text:1.15.0'
implementation 'com.google.code.gson:gson:2.14.0'
// jakarta is only used for annotations, we do not add it as implementation dependency on purpose to avoid forcing
// users to use jakarta jars in their project when they might not even be using JPA or JAXB at all
compileOnly 'jakarta.persistence:jakarta.persistence-api:3.1.0' // jakarta 3.1 is Jakarta EE 10, jakarta 3.2 would imply migration to Jakarta EE 11
compileOnly 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.5'
compileOnly 'jakarta.validation:jakarta.validation-api:3.1.1'
testImplementation 'com.networknt:json-schema-validator:2.0.4'
testImplementation 'jakarta.persistence:jakarta.persistence-api:3.1.0'
testImplementation 'jakarta.validation:jakarta.validation-api:3.1.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.14.4'
testImplementation 'org.junit.platform:junit-platform-launcher:1.14.4'
testImplementation 'org.assertj:assertj-core:3.27.6'
testImplementation 'org.xmlunit:xmlunit-core:2.13.0'
testImplementation 'org.xmlunit:xmlunit-matchers:2.13.0'
testImplementation 'org.xmlunit:xmlunit-assertj:2.13.0'
}
sourceSets.named('main') {
java {
setSrcDirs(['src/main/java', 'src/generated/java'])
}
}
test {
useJUnitPlatform()
}
tasks.withType(Jar).configureEach {
manifest.attributes(
'Specification-Title': 'Prowide Core',
'Specification-Version': project.version,
'Specification-Vendor': "${SRU}",
'Implementation-Title': 'Prowide Core',
'Implementation-Version': project.version,
'Implementation-Vendor': 'www.prowidesoftware.com',
'Built-OS': System.getProperty('os.name'),
'Source-Compatibility': JavaVersion.VERSION_11,
'Target-Compatibility': JavaVersion.VERSION_11,
'Built-Date': new Date().format("yyyy-MM-dd"),
'Automatic-Module-Name': 'com.prowidesoftware.core'
)
}
tasks.register('sourcesJar', Jar) {
dependsOn classes
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
static def formattedDate() {
new Date().format('dd MMM yyyy')
}
javadoc {
failOnError true
options.overview = "overview.html"
options.header = "${version}"
options.windowTitle = "Prowide Core API Reference"
options.footer="${SRU}, generated ${formattedDate()}"
// this will fail when the option is not available (older JDK)
options.addBooleanOption("-allow-script-in-comments", true)
options.bottom = '<script src="//static.getclicky.com/js"></script><script>try{ clicky.init(101039278); }catch(e){}</script>'
exclude "**/internal/**"
options.addStringOption('Xdoclint:none', '-quiet')
}
tasks.register('javadocJar', Jar) {
dependsOn javadoc
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar, sourcesJar
}
project.ext {
nexusRepo = project.version.endsWith('-SNAPSHOT') ? 'maven-snapshots' : 'maven-releases'
}
publishing {
publications {
mavenJava(MavenPublication) {
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
afterEvaluate {
from components.java
artifactId = 'pw-swift-core'
groupId = 'com.prowidesoftware'
version = "${version}"
pom {
name = 'Prowide Core'
description = 'Prowide Library for SWIFT messages'
url = 'https://www.prowidesoftware.com'
scm {
url = 'https://github.com/prowide/prowide-core.git'
connection = 'git@github.com:prowide/prowide-core.git'
}
inceptionYear = '2006'
licenses {
license {
name = 'Apache License Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0'
distribution = 'repo'
}
}
developers {
developer {
id = 'zubri'
name = 'Sebastian Zubrinic'
email = 'sebastian@prowidesoftware.com'
}
}
organization {
name = 'Prowide'
url = 'https://www.prowidesoftware.com'
}
}
}
}
}
// Prowide repo releases
if (project.hasProperty('prowideRepo')) {
repositories {
maven {
url "${project.prowideRepo}/repository/${nexusRepo}/"
credentials {
username "${project.prowideRepoUser}"
password "${project.prowideRepoPass}"
}
}
}
} else {
project.logger.info('Prowide publishing disabled because repository properties are undefined')
}
}
jar.finalizedBy generatePomFileForMavenJavaPublication
tasks.withType(GenerateModuleMetadata).configureEach {
// to avoid metadata in the generated pom.xml files
enabled = false
}
// OSS Sonatype releases
signing {
required { project.hasProperty('SONATYPE_RELEASE') }
sign publishing.publications.mavenJava
}
java {
withJavadocJar()
withSourcesJar()
}
// Zip GitHub releases
distributions {
main {
contents {
from javadocJar
from sourcesJar
into ('lib') {
from (project.configurations.runtimeClasspath)
}
from files('LICENSE.txt')
from files('CHANGELOG.md')
from ("$buildDir/publications/mavenJava/pom-default.xml") {
rename ".*", "pom.xml"
}
}
}
}
distTar.enabled = false
distZip {
dependsOn generatePomFileForMavenJavaPublication
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.register('generateChecksums') {
dependsOn jar, sourcesJar, javadocJar, generatePomFileForMavenJavaPublication
description 'Generates MD5 and SHA1 checksums for artifacts and POM'
doLast {
def filesToChecksum = [
"${buildDir}/libs/${project.archivesBaseName}-${project.version}.jar",
"${buildDir}/libs/${project.archivesBaseName}-${project.version}-sources.jar",
"${buildDir}/libs/${project.archivesBaseName}-${project.version}-javadoc.jar",
"${buildDir}/publications/mavenJava/pom-default.xml"
]
filesToChecksum.each { filePath ->
def file = file(filePath)
if (file.exists()) {
// Generate MD5
def md5Digest = java.security.MessageDigest.getInstance('MD5')
file.withInputStream { stream ->
byte[] buffer = new byte[8192]
int read
while ((read = stream.read(buffer)) > 0) {
md5Digest.update(buffer, 0, read)
}
}
def md5Checksum = md5Digest.digest().encodeHex().toString()
new File("${file}.md5").text = md5Checksum
// Generate SHA1
def sha1Digest = java.security.MessageDigest.getInstance('SHA1')
file.withInputStream { stream ->
byte[] buffer = new byte[8192]
int read
while ((read = stream.read(buffer)) > 0) {
sha1Digest.update(buffer, 0, read)
}
}
def sha1Checksum = sha1Digest.digest().encodeHex().toString()
new File("${file}.sha1").text = sha1Checksum
} else {
throw new GradleException("File not found: ${filePath}")
}
}
}
}
// Alternative (manual) upload artifact for Maven Central Repository
tasks.register('bundle', Zip) {
dependsOn build, signMavenJavaPublication, generateChecksums
onlyIf {
project.hasProperty('SONATYPE_RELEASE')
}
description 'Creates the bundle.zip for Maven Central distribution with Maven Repository Layout'
def baseName = "${project.archivesBaseName}-${project.version}"
def mavenPath = "com/prowidesoftware/${project.archivesBaseName}/${project.version}/"
into(mavenPath) {
from("${buildDir}/libs/${baseName}.jar") { rename { "${baseName}.jar" } }
from("${buildDir}/libs/${baseName}-sources.jar") { rename { "${baseName}-sources.jar" } }
from("${buildDir}/libs/${baseName}-javadoc.jar") { rename { "${baseName}-javadoc.jar" } }
from("${buildDir}/libs/${baseName}.jar.asc") { rename { "${baseName}.jar.asc" } }
from("${buildDir}/libs/${baseName}-sources.jar.asc") { rename { "${baseName}-sources.jar.asc" } }
from("${buildDir}/libs/${baseName}-javadoc.jar.asc") { rename { "${baseName}-javadoc.jar.asc" } }
from("${buildDir}/libs/${baseName}.jar.md5") { rename { "${baseName}.jar.md5" } }
from("${buildDir}/libs/${baseName}-sources.jar.md5") { rename { "${baseName}-sources.jar.md5" } }
from("${buildDir}/libs/${baseName}-javadoc.jar.md5") { rename { "${baseName}-javadoc.jar.md5" } }
from("${buildDir}/libs/${baseName}.jar.sha1") { rename { "${baseName}.jar.sha1" } }
from("${buildDir}/libs/${baseName}-sources.jar.sha1") { rename { "${baseName}-sources.jar.sha1" } }
from("${buildDir}/libs/${baseName}-javadoc.jar.sha1") { rename { "${baseName}-javadoc.jar.sha1" } }
from("${buildDir}/publications/mavenJava/pom-default.xml") { rename { "${baseName}.pom" } }
from("${buildDir}/publications/mavenJava/pom-default.xml.asc") { rename { "${baseName}.pom.asc" } }
from("${buildDir}/publications/mavenJava/pom-default.xml.md5") { rename { "${baseName}.pom.md5" } }
from("${buildDir}/publications/mavenJava/pom-default.xml.sha1") { rename { "${baseName}.pom.sha1" } }
}
archiveFileName.set('bundle.zip')
}
tasks.withType(Test).configureEach {
// DeprecationUtils#setEnv reflects into java.lang.ProcessEnvironment (and falls back to
// java.util.Collections$UnmodifiableMap) on purpose; open both packages so the JVM does
// not print illegal-access warnings on JDK 11+.
jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED', '--add-opens=java.base/java.util=ALL-UNNAMED'
doFirst {
println 'Running test on ' + getJavaLauncher().get().getMetadata().getInstallationPath()
}
}
tasks.register('testOn17', Test) {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(17)
}
}
tasks.register('testOn21', Test) {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(21)
}
}
// Runs the suite on a Java 25 toolchain to verify the Java 11 artifacts execute correctly on Java 25.
// Needed to catch JDK-version behavior changes (e.g. JDK 24 tightened the JAXP entity size limits) that
// cannot manifest on the Java 11/17/21 the build otherwise uses. JDK 25 must be available to the Gradle
// toolchain (CI passes -Porg.gradle.java.installations.paths=/pw/dev/jdk25).
tasks.register('testOn25', Test) {
description = 'Runs tests using a Java 25 toolchain to verify compatibility'
group = 'verification'
useJUnitPlatform()
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(25)
}
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
reports {
html.required = true
html.outputLocation = layout.buildDirectory.dir("reports/tests/testOn25")
}
binaryResultsDirectory = layout.buildDirectory.dir("test-results/testOn25")
dependsOn testClasses
}
jacocoTestReport {
reports {
xml.required.set(true)
csv.required.set(false)
html.required.set(false)
}
// exclude generated code
afterEvaluate {
getClassDirectories().setFrom(classDirectories.files.collect {
fileTree(dir: it, exclude: [
'**/SchemeConstants**',
'**/mt0xx/**',
'**/mt1xx/**',
'**/mt2xx/**',
'**/mt3xx/**',
'**/mt4xx/**',
'**/mt5xx/**',
'**/mt6xx/**',
'**/mt7xx/**',
'**/mt8xx/**',
'**/mt9xx/**'
])
})
}
}
test.finalizedBy jacocoTestReport
quality {
strict = false
// we limit this to spotbugs for the moment
checkstyle = false
codenarc = false
cpd = false
pmd = false
spotbugsEffort = 'min'
spotbugsMaxRank = 8
}
apply plugin: 'com.diffplug.spotless'
spotless {
java {
target '**/src/main/java/**/*.java', '**/src/test/java/**/*.java'
palantirJavaFormat()
}
}
test.finalizedBy(spotlessCheck)