diff --git a/jda-commands/build.gradle.kts b/jda-commands/build.gradle.kts index 2667382f..875edb6a 100644 --- a/jda-commands/build.gradle.kts +++ b/jda-commands/build.gradle.kts @@ -1,7 +1,10 @@ +import java.security.MessageDigest + plugins { `java-library` `maven-publish` jacoco + signing } repositories { @@ -23,16 +26,10 @@ dependencies { testImplementation(libs.org.junit.jupiter.junit.jupiter.engine) } -group = "com.github.kaktushose" +group = "io.github.kaktushose" version = "4.0.0-beta.4" description = "jda-commands" -publishing { - publications.create("maven") { - from(components["java"]) - } -} - java { targetCompatibility = JavaVersion.VERSION_23 sourceCompatibility = JavaVersion.VERSION_23 @@ -43,6 +40,133 @@ java { withJavadocJar() } +publishing { + publications { + create("mavenJava") { + from(components["java"]) + pom { + name.set("JDA-Commands") + description.set("A declarative, annotation driven interaction framework for JDA") + url.set("https://github.com/Kaktushose/jda-commands") + + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0") + } + } + + developers { + developer { + name.set("Kaktushose") + } + developer { + name.set("Goldmensch") + } + } + + scm { + connection.set("scm:git:git://github.com/kaktushose/jda-commands.git") + developerConnection.set("scm:git:ssh://github.com/kaktushose/jda-commands.git") + url.set("https://github.com/Kaktushose/jda-commands") + } + } + } + } +} + +signing { + useGpgCmd() + sign(publishing.publications["mavenJava"]) +} + +// Task to generate checksums +tasks.register("generateChecksums") { + group = "verification" + description = "Generates SHA1 and MD5 checksums for artifacts" + + doLast { + val artifacts = listOf( + tasks.named("javadocJar").get().archiveFile.get().asFile, + tasks.named("sourcesJar").get().archiveFile.get().asFile, + tasks.named("jar").get().archiveFile.get().asFile, + file("${layout.buildDirectory.asFile.get().absolutePath}/publications/mavenJava/pom-default.xml") + ) + + artifacts.forEach { artifact -> + println(artifact.absolutePath) + val sha1File = File(artifact.absolutePath + ".sha1") + val md5File = File(artifact.absolutePath + ".md5") + + sha1File.writeText(artifact.inputStream().use { it.readBytes().sha1Hex() }) + md5File.writeText(artifact.inputStream().use { it.readBytes().md5Hex() }) + } + } +} + +// Task to create the ZIP file +tasks.register("packageForMavenCentral") { + group = "build" + val buildDir = layout.buildDirectory.asFile.get().absolutePath + val destinationDir = "io/github/kaktushose/jda-commands/${version}" + dependsOn("generateChecksums") + dependsOn("signMavenJavaPublication") + + from(tasks.named("javadocJar")) { + into(destinationDir) + } + from(tasks.named("sourcesJar")) { + into(destinationDir) + } + from(tasks.named("jar")) { + into(destinationDir) + } + from("$buildDir/publications/mavenJava") { + include("pom-default.xml") + into(destinationDir) + rename("pom-default.xml", "${project.name}-${version}.pom") + } + from("$buildDir/publications/mavenJava") { + include("pom-default.xml.asc") + into(destinationDir) + rename("pom-default.xml.asc", "${project.name}-${version}.pom.asc") + } + from("$buildDir/publications/mavenJava") { + include("pom-default.xml.md5") + into(destinationDir) + rename("pom-default.xml.md5", "${project.name}-${version}.pom.md5") + } + from("$buildDir/publications/mavenJava") { + include("pom-default.xml.sha1") + into(destinationDir) + rename("pom-default.xml.sha1", "${project.name}-${version}.pom.sha1") + } + from("$buildDir/libs") { + include("*.asc", "*.md5", "*sha1") + into(destinationDir) + } + archiveFileName.set("${project.name}-${version}-maven-central.zip") + destinationDirectory.set(file("$buildDir/distributions")) +} + +// Utility functions for checksums +fun ByteArray.sha1Hex(): String { + return MessageDigest.getInstance("SHA-1") + .digest(this) + .joinToString("") { "%02x".format(it) } +} + +fun ByteArray.md5Hex(): String { + return MessageDigest.getInstance("MD5") + .digest(this) + .joinToString("") { "%02x".format(it) } +} + +tasks.named("build") { + dependsOn("generatePomFileForMavenJavaPublication") + dependsOn("packageForMavenCentral") +} + tasks.test { useJUnitPlatform() @@ -60,7 +184,7 @@ tasks.jacocoTestReport { tasks.withType { val options = options as StandardJavadocDocletOptions options.encoding = "UTF-8" - + options.addBooleanOption("Xdoclint:none,-missing", true) options.tags("apiNote:a:API Note:", "implSpec:a:Implementation Requirements:", "implNote:a:Implementation Note:") options.overview = "src/main/javadoc/overview.md" // doesn't work anyway, f u gradle