|
1 | 1 | import org.jetbrains.kotlin.gradle.dsl.JvmTarget |
2 | 2 | import java.util.Base64 |
| 3 | +import java.security.MessageDigest |
| 4 | +import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven |
| 5 | +import org.gradle.api.artifacts.repositories.MavenArtifactRepository |
3 | 6 |
|
4 | 7 | plugins { |
5 | 8 | alias(libs.plugins.kotlinMultiplatform) |
@@ -133,6 +136,106 @@ publishing { |
133 | 136 | } |
134 | 137 | } |
135 | 138 |
|
| 139 | +tasks.withType<GenerateModuleMetadata>().configureEach { |
| 140 | + enabled = true |
| 141 | +} |
| 142 | + |
| 143 | +// Task to generate MD5 and SHA1 checksums for Maven Central |
| 144 | +tasks.register("generateChecksums") { |
| 145 | + group = "publishing" |
| 146 | + description = "Generate MD5 and SHA1 checksums for Maven Central artifacts" |
| 147 | + |
| 148 | + dependsOn("publishAllPublicationsToMavenCentralLocalRepository") |
| 149 | + |
| 150 | + doLast { |
| 151 | + val stagingDir = project.layout.buildDirectory.dir("maven-central-staging").get().asFile |
| 152 | + if (!stagingDir.exists()) { |
| 153 | + logger.warn("Staging directory does not exist: $stagingDir") |
| 154 | + return@doLast |
| 155 | + } |
| 156 | + |
| 157 | + var checksumCount = 0 |
| 158 | + stagingDir.walk().forEach { file -> |
| 159 | + if (file.isFile && !file.name.endsWith(".md5") && !file.name.endsWith(".sha1") |
| 160 | + && !file.name.endsWith(".sha256") && !file.name.endsWith(".sha512") |
| 161 | + && !file.name.endsWith(".asc")) { |
| 162 | + |
| 163 | + // Generate MD5 |
| 164 | + val md5File = File(file.parentFile, "${file.name}.md5") |
| 165 | + if (!md5File.exists()) { |
| 166 | + val md5 = MessageDigest.getInstance("MD5") |
| 167 | + .digest(file.readBytes()) |
| 168 | + .joinToString("") { byte -> "%02x".format(byte) } |
| 169 | + md5File.writeText(md5) |
| 170 | + checksumCount++ |
| 171 | + logger.lifecycle("Generated MD5: ${md5File.relativeTo(stagingDir)}") |
| 172 | + } |
| 173 | + |
| 174 | + // Generate SHA1 |
| 175 | + val sha1File = File(file.parentFile, "${file.name}.sha1") |
| 176 | + if (!sha1File.exists()) { |
| 177 | + val sha1 = MessageDigest.getInstance("SHA-1") |
| 178 | + .digest(file.readBytes()) |
| 179 | + .joinToString("") { byte -> "%02x".format(byte) } |
| 180 | + sha1File.writeText(sha1) |
| 181 | + checksumCount++ |
| 182 | + logger.lifecycle("Generated SHA1: ${sha1File.relativeTo(stagingDir)}") |
| 183 | + } |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + logger.lifecycle("Generated $checksumCount checksum files in $stagingDir") |
| 188 | + } |
| 189 | +} |
| 190 | + |
| 191 | +// Task to publish only Android artifacts (workaround for iOS compilation issues) |
| 192 | +tasks.register("publishAndroidWithChecksums") { |
| 193 | + group = "publishing" |
| 194 | + description = "Publish only Android artifacts with checksums to Maven Central" |
| 195 | + |
| 196 | + dependsOn("publishAndroidReleasePublicationToMavenCentralLocalRepository") |
| 197 | + |
| 198 | + doLast { |
| 199 | + val stagingDir = project.layout.buildDirectory.dir("maven-central-staging").get().asFile |
| 200 | + if (!stagingDir.exists()) { |
| 201 | + logger.warn("Staging directory does not exist: $stagingDir") |
| 202 | + return@doLast |
| 203 | + } |
| 204 | + |
| 205 | + var checksumCount = 0 |
| 206 | + stagingDir.walk().forEach { file -> |
| 207 | + if (file.isFile && !file.name.endsWith(".md5") && !file.name.endsWith(".sha1") |
| 208 | + && !file.name.endsWith(".sha256") && !file.name.endsWith(".sha512") |
| 209 | + && !file.name.endsWith(".asc")) { |
| 210 | + |
| 211 | + // Generate MD5 |
| 212 | + val md5File = File(file.parentFile, "${file.name}.md5") |
| 213 | + if (!md5File.exists()) { |
| 214 | + val md5 = MessageDigest.getInstance("MD5") |
| 215 | + .digest(file.readBytes()) |
| 216 | + .joinToString("") { byte -> "%02x".format(byte) } |
| 217 | + md5File.writeText(md5) |
| 218 | + checksumCount++ |
| 219 | + logger.lifecycle("Generated MD5: ${md5File.relativeTo(stagingDir)}") |
| 220 | + } |
| 221 | + |
| 222 | + // Generate SHA1 |
| 223 | + val sha1File = File(file.parentFile, "${file.name}.sha1") |
| 224 | + if (!sha1File.exists()) { |
| 225 | + val sha1 = MessageDigest.getInstance("SHA-1") |
| 226 | + .digest(file.readBytes()) |
| 227 | + .joinToString("") { byte -> "%02x".format(byte) } |
| 228 | + sha1File.writeText(sha1) |
| 229 | + checksumCount++ |
| 230 | + logger.lifecycle("Generated SHA1: ${sha1File.relativeTo(stagingDir)}") |
| 231 | + } |
| 232 | + } |
| 233 | + } |
| 234 | + |
| 235 | + logger.lifecycle("Generated $checksumCount checksum files for Android artifacts in $stagingDir") |
| 236 | + } |
| 237 | +} |
| 238 | + |
136 | 239 | signing { |
137 | 240 | val signingKeyBase64 = project.findProperty("signing.key") as String? |
138 | 241 | val signingPassword = project.findProperty("signing.password") as String? ?: "" |
|
0 commit comments