-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
312 lines (263 loc) Β· 11.9 KB
/
build.gradle.kts
File metadata and controls
312 lines (263 loc) Β· 11.9 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
import java.security.MessageDigest
import java.util.*
plugins {
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.kotlin.atomicfu) apply false
alias(libs.plugins.ksp) apply false
}
val localProperties = Properties().apply {
val localFile = rootProject.file("local.properties")
if (localFile.exists()) {
load(localFile.inputStream())
}
}
val versionPropsFile = rootProject.file("version.properties")
val versionProps = Properties().apply {
if (versionPropsFile.exists()) {
load(versionPropsFile.inputStream())
}
}
group = "codes.yousef.aether"
version = versionProps.getProperty("VERSION") ?: "0.1.0-SNAPSHOT"
allprojects {
group = rootProject.group
version = rootProject.version
repositories {
google()
mavenCentral()
}
}
subprojects {
apply(plugin = "maven-publish")
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
from(rootProject.file("README.md"))
}
extensions.configure<PublishingExtension> {
publications.withType<MavenPublication> {
artifact(javadocJar)
pom {
name.set(project.name)
description.set("Aether - A Kotlin Multiplatform Web Framework")
url.set("https://github.com/codeyousef/aether")
licenses {
license {
name.set("MIT")
url.set("https://opensource.org/licenses/MIT")
}
}
developers {
developer {
id.set("codeyousef")
name.set("Yousef")
email.set("code.yousef@gmail.com")
}
}
scm {
url.set("https://github.com/codeyousef/aether")
connection.set("scm:git:git://github.com/codeyousef/aether.git")
developerConnection.set("scm:git:ssh://github.com/codeyousef/aether.git")
}
}
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
}
// Custom task to bundle and publish artifacts to Maven Central Portal
tasks.register("publishToCentralPortalManually") {
group = "publishing"
description = "Publish to Maven Central using Central Portal API"
dependsOn(subprojects.map { ":${it.name}:publishToMavenLocal" })
doLast {
val username = localProperties.getProperty("mavenCentralUsername")
?: System.getenv("mavenCentralUsername")
?: throw GradleException("mavenCentralUsername not found")
val password = localProperties.getProperty("mavenCentralPassword")
?: System.getenv("mavenCentralPassword")
?: throw GradleException("mavenCentralPassword not found")
println("π Publishing to Maven Central via Central Portal API...")
println("π¦ Username: $username")
// Create bundle directory with proper Maven structure
val bundleDir = file("${layout.buildDirectory.get()}/central-portal-bundle")
bundleDir.deleteRecursively()
bundleDir.mkdirs()
// List of modules to publish
val modules = listOf(
"aether-core",
"aether-signals",
"aether-tasks",
"aether-channels",
"aether-db",
"aether-web",
"aether-ui",
"aether-net",
"aether-ksp",
"aether-auth",
"aether-forms",
"aether-admin",
"aether-grpc"
)
// List of variants for each module
val variants = listOf("", "-jvm", "-wasm-js", "-wasm-wasi")
val allFilesToProcess = mutableListOf<File>()
var foundModuleCount = 0
var missingModuleCount = 0
val mavenLocalRoot = file("${System.getProperty("user.home")}/.m2/repository/codes/yousef/aether")
println("π Looking for artifacts in: $mavenLocalRoot")
if (!mavenLocalRoot.exists()) {
throw GradleException("Maven local repository path does not exist: $mavenLocalRoot. Did publishToMavenLocal run?")
}
modules.forEach { module ->
variants.forEach { variant ->
val artifactId = "$module$variant"
val version = project.version.toString()
// Construct path in local repo
val localMavenDir = file("${mavenLocalRoot.absolutePath}/$artifactId/$version")
if (localMavenDir.exists()) {
foundModuleCount++
val mavenPath = "codes/yousef/aether/$artifactId/$version"
val targetDir = file("$bundleDir/$mavenPath")
targetDir.mkdirs()
val files = localMavenDir.listFiles() ?: emptyArray()
val artifactFiles = files.filter { file ->
(file.name.endsWith(".jar") || file.name.endsWith(".pom") || file.name.endsWith(".klib") || file.name.endsWith(
".module"
)) &&
!file.name.endsWith(".md5") && !file.name.endsWith(".sha1") && !file.name.endsWith(".asc")
}
if (artifactFiles.isNotEmpty()) {
println("π¦ Processing $artifactId (${artifactFiles.size} files)...")
artifactFiles.forEach { file ->
file.copyTo(File(targetDir, file.name), overwrite = true)
allFilesToProcess.add(File(targetDir, file.name))
}
} else {
println("β οΈ Directory exists but no artifact files found for $artifactId")
}
} else {
missingModuleCount++
// Only warn for base modules without variant suffix, as variants may not exist for all modules
if (variant.isEmpty()) {
println("β οΈ No artifacts found for $artifactId at $localMavenDir")
}
}
}
}
println("π Found $foundModuleCount module variants, $missingModuleCount not found")
if (allFilesToProcess.isEmpty()) {
throw GradleException("No Maven artifacts found. Make sure publishToMavenLocal ran successfully.")
}
println("π Generating checksums and signatures...")
allFilesToProcess.forEach { file ->
// Generate MD5 checksum
val md5Hash = MessageDigest.getInstance("MD5")
.digest(file.readBytes())
.joinToString("") { byte -> "%02x".format(byte) }
File(file.parent, "${file.name}.md5").writeText(md5Hash)
// Generate SHA1 checksum
val sha1Hash = MessageDigest.getInstance("SHA-1")
.digest(file.readBytes())
.joinToString("") { byte -> "%02x".format(byte) }
File(file.parent, "${file.name}.sha1").writeText(sha1Hash)
// Generate GPG signature
val sigFile = File(file.parent, "${file.name}.asc")
println(" Creating GPG signature for ${file.name}...")
val privateKeyFile = rootProject.file("private-key.asc")
if (!privateKeyFile.exists()) {
throw GradleException("private-key.asc not found. Cannot sign artifacts.")
}
val signScript = rootProject.file("sign-artifact.sh")
if (!signScript.exists()) {
throw GradleException("sign-artifact.sh not found. Cannot sign artifacts.")
}
val signingPassword = localProperties.getProperty("signingPassword")
?: System.getenv("signingPassword")
?: throw GradleException("signingPassword not found")
exec {
commandLine(
"bash",
signScript.absolutePath,
signingPassword,
privateKeyFile.absolutePath,
sigFile.absolutePath,
file.absolutePath
)
}
}
// Verify we have files to publish
val filesInBundle = bundleDir.walkTopDown().filter { it.isFile }.toList()
println("π¦ Total files in bundle: ${filesInBundle.size}")
if (filesInBundle.isEmpty()) {
throw GradleException("Bundle directory is empty. No artifacts to publish.")
}
// Show bundle structure for debugging
println("π Bundle contents:")
filesInBundle.take(20).forEach { println(" - ${it.relativeTo(bundleDir)}") }
if (filesInBundle.size > 20) {
println(" ... and ${filesInBundle.size - 20} more files")
}
println("π¦ Zipping bundle...")
val zipFile = file("${layout.buildDirectory.get()}/central-portal-bundle.zip")
if (zipFile.exists()) zipFile.delete()
exec {
workingDir = bundleDir
commandLine("zip", "-r", zipFile.absolutePath, ".")
}
val bundleSizeKB = zipFile.length() / 1024
println("π Bundle size: $bundleSizeKB KB")
if (bundleSizeKB == 0L) {
throw GradleException("Bundle zip file is empty!")
}
println("π Uploading to Central Portal...")
// Base64 encode credentials for UserToken auth
val userPass = "$username:$password"
val userPassBase64 = java.util.Base64.getEncoder().encodeToString(userPass.toByteArray())
// Temp files for curl output
val responseFile = file("${layout.buildDirectory.get()}/central-portal-response.txt")
val httpCodeFile = file("${layout.buildDirectory.get()}/central-portal-httpcode.txt")
val curlStderrFile = file("${layout.buildDirectory.get()}/central-portal-curl-stderr.txt")
// Upload using curl with proper error handling
exec {
commandLine(
"bash", "-c", """
HTTP_CODE=${'$'}(curl --request POST \
--url "https://central.sonatype.com/api/v1/publisher/upload?publishingType=AUTOMATIC" \
--header "Authorization: UserToken $userPassBase64" \
--form "bundle=@${zipFile.absolutePath}" \
--write-out "%{http_code}" \
--output "${responseFile.absolutePath}" \
--fail-with-body \
--silent \
2>"${curlStderrFile.absolutePath}")
echo "${'$'}HTTP_CODE" > "${httpCodeFile.absolutePath}"
echo "HTTP Code: ${'$'}HTTP_CODE"
echo "Response:"
cat "${responseFile.absolutePath}" || echo "(empty)"
echo ""
if [ "${'$'}HTTP_CODE" -ge 200 ] && [ "${'$'}HTTP_CODE" -lt 300 ]; then
exit 0
else
echo "Curl stderr:"
cat "${curlStderrFile.absolutePath}" || echo "(empty)"
exit 1
fi
""".trimIndent()
)
}
// Read and display results
val httpCode = if (httpCodeFile.exists()) httpCodeFile.readText().trim() else "unknown"
val response = if (responseFile.exists()) responseFile.readText().trim() else ""
println("π HTTP Status Code: $httpCode")
println("π Response Body: $response")
if (httpCode.toIntOrNull()?.let { it < 200 || it >= 300 } != false) {
val stderr = if (curlStderrFile.exists()) curlStderrFile.readText().trim() else ""
throw GradleException("Failed to upload to Maven Central. HTTP Code: $httpCode, Response: $response, Stderr: $stderr")
}
println("β
Upload complete!")
}
}