-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
204 lines (166 loc) · 6.86 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
import java.nio.file.Files
import java.security.MessageDigest
plugins {
id 'java-library'
id 'maven-publish'
id 'signing'
}
group = 'io.github.waileong'
version = '1.0.4'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
withJavadocJar()
withSourcesJar()
}
repositories {
mavenCentral()
}
dependencies {
// Spring Boot BOM for dependency management
implementation platform("org.springframework.boot:spring-boot-dependencies:$spring_boot_version")
implementation("org.apache.commons:commons-lang3")
// Spring Boot starters
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-web")
// Additional dependencies
implementation("org.apache.commons:commons-pool2:$commons_pool2_version")
implementation("io.jsonwebtoken:jjwt-api:$jjwt_version")
implementation("io.jsonwebtoken:jjwt-impl:$jjwt_version")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:$jjwt_version")
// Annotation processor
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor:$spring_boot_version")
// Testing dependencies
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.assertj:assertj-core")
}
// Java compile options
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.deprecation = true
options.compilerArgs.add("-parameters")
}
// Signing configuration
signing {
sign publishing.publications
}
// Publishing configuration
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom {
name = 'Spring Boot FCM Push Notification'
description = 'A Spring Boot library for Firebase Cloud Messaging (FCM) push notifications.'
url = 'https://github.com/waileong/spring-boot-fcm-push-notification'
licenses {
license {
name = 'MIT License'
url = 'https://opensource.org/licenses/MIT'
}
}
developers {
developer {
id = 'waileong'
name = 'Wai Leong'
email = 'waileonggithub@gmail.com'
}
}
scm {
connection = 'scm:git:git@github.com:waileong/spring-boot-fcm-push-notification.git'
developerConnection = 'scm:git:ssh://github.com/waileong/spring-boot-fcm-push-notification.git'
url = 'https://github.com/waileong/spring-boot-fcm-push-notification'
}
}
}
}
}
test {
useJUnitPlatform()
}
// Register the Copy task to prepare the files
tasks.register('prepareBundleJars', Copy) {
// Define the destination directory within the build directory using the specific folder structure
def tempDir = "$buildDir/tempBundle/io/github/waileong/spring-boot-fcm/$version"
into(tempDir)
// Include the main jar, sourcesJar, and javadocJar by copying them
from(tasks.named('jar').map { it.archiveFile })
from(tasks.named('javadocJar').map { it.archiveFile })
from(tasks.named('sourcesJar').map { it.archiveFile })
// Include the POM file generated by the maven-publish plugin and its .asc signature file
def generateMavenPomTask = tasks.withType(GenerateMavenPom).named("generatePomFileForMavenJavaPublication")
def pomFile = generateMavenPomTask.map { it.destination }.get()
from(pomFile) {
// Rename the POM file to pom.xml
rename { String fileName -> "$rootProject.name-$version" + ".pom" }
}
def pomAscFile = file("${pomFile}.asc")
if (pomAscFile.exists()) {
from(pomAscFile) {
// Rename the .asc signature file to pom.xml.asc
rename { String fileName -> "$rootProject.name-$version" + ".pom.asc" }
}
}
// Include all .asc signature files dynamically
doFirst {
publishing.publications.mavenJava.artifacts.forEach { artifact ->
def artifactFile = artifact.file
def ascFile = file("${artifactFile}.asc")
if (ascFile.exists()) {
from(ascFile)
}
}
}
// Set the duplicatesStrategy to 'exclude' to handle duplicate entries
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
// Create a custom task to generate checksum files
task generateChecksums(type: DefaultTask) {
dependsOn 'prepareBundleJars'
doLast {
// Define the directory containing the files you want to generate checksums for
def targetDir = file("$buildDir/tempBundle/io/github/waileong/spring-boot-fcm/$version")
// Iterate over the files in the directory
targetDir.eachFile { file ->
if (file.isFile() && (file.name.endsWith(".jar") || file.name.endsWith(".pom"))) {
// Generate SHA-1 checksum
def sha1Digest = MessageDigest.getInstance("SHA-1")
def sha1Checksum = sha1Digest.digest(Files.readAllBytes(file.toPath()))
// Generate MD5 checksum
def md5Digest = MessageDigest.getInstance("MD5")
def md5Checksum = md5Digest.digest(Files.readAllBytes(file.toPath()))
// Create and write SHA-1 checksum file
def sha1File = new File(targetDir, "${file.name}.sha1")
sha1File.text = sha1Checksum.collect { String.format("%02x", it) }.join()
// Create and write MD5 checksum file
def md5File = new File(targetDir, "${file.name}.md5")
md5File.text = md5Checksum.collect { String.format("%02x", it) }.join()
}
}
}
}
// Register the Zip task that depends on the prepareBundleJars task
tasks.register('bundleJars', Zip) {
dependsOn 'generateChecksums'
// Configure the ZIP archive's destination and name
archiveBaseName.set(rootProject.name)
archiveVersion.set(version)
destinationDirectory.set(file("$buildDir/distributions"))
// Specify the directory to zip, which is the specific folder structure used in prepareBundleJars task
def tempDir = "$buildDir/tempBundle"
from(tempDir) {
// Exclude pom-default.xml from being included in the ZIP
exclude("**/pom-default.xml")
}
// Include the generated SHA-1 and MD5 checksum files in the ZIP
from(tempDir) {
include("**/*.sha1", "**/*.md5")
into("/")
}
// Set the duplicatesStrategy to 'exclude' to handle duplicate entries
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
// Ensure 'prepareBundleJars' runs after artifacts are built and signed
prepareBundleJars.dependsOn 'assemble', 'signMavenJavaPublication'