From 70f93bfadcae6d8c0062cccc1e3a8d759d3341eb Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 14 Oct 2023 04:38:39 +0200 Subject: [PATCH] build: Publish artifacts on Jitpack --- build.gradle.kts | 68 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e1efe335f..ec4c98b8f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,9 @@ +import org.gradle.kotlin.dsl.support.listFilesOrdered + plugins { kotlin("jvm") version "1.8.20" alias(libs.plugins.ksp) + `maven-publish` } group = "app.revanced" @@ -27,6 +30,7 @@ dependencies { implementation(libs.guava) // Used in JsonGenerator. implementation(libs.gson) + // A dependency to the Android library unfortunately fails the build, which is why this is required. compileOnly(project("dummy")) @@ -40,40 +44,74 @@ kotlin { tasks { register("generateBundle") { description = "Generate dex files from build and bundle them in the jar file" + dependsOn(build) doLast { - val androidHome = System.getenv("ANDROID_HOME") ?: throw GradleException("ANDROID_HOME not found") - val d8 = "${androidHome}/build-tools/33.0.1/d8" - val input = configurations.archives.get().allArtifacts.files.files.first().absolutePath - val work = layout.buildDirectory.dir("libs").get().asFile + val d8 = File(System.getenv("ANDROID_HOME")).resolve("build-tools") + .listFilesOrdered().last().resolve("d8").absolutePath + + val artifacts = configurations.archives.get().allArtifacts.files.files.first().absolutePath + val workingDirectory = layout.buildDirectory.dir("libs").get().asFile exec { - workingDir = work - commandLine = listOf(d8, input) + workingDir = workingDirectory + commandLine = listOf(d8, artifacts) } exec { - workingDir = work - commandLine = listOf("zip", "-u", input, "classes.dex") + workingDir = workingDirectory + commandLine = listOf("zip", "-u", artifacts, "classes.dex") } } } register("generateMeta") { description = "Generate metadata for this bundle" + dependsOn(build) classpath = sourceSets["main"].runtimeClasspath mainClass.set("app.revanced.meta.PatchesFileGenerator") } - // Dummy task to fix the Gradle semantic-release plugin. - // Remove this if you forked it to support building only. - // Tracking issue: https://github.com/KengoTODA/gradle-semantic-release-plugin/issues/435 - register("publish") { - group = "publish" - description = "Dummy task" - dependsOn(named("generateBundle"), named("generateMeta")) + // Required to run tasks because Gradle semantic-release plugin runs the publish task. + // Tracking: https://github.com/KengoTODA/gradle-semantic-release-plugin/issues/435 + named("publish") { + dependsOn("generateBundle") + dependsOn("generateMeta") } } + +publishing { + publications { + create("revanced-patches-publication") { + from(components["java"]) + + pom { + name = "ReVanced Patches" + description = "Patches for ReVanced." + url = "https://revanced.app" + + licenses { + license { + name = "GNU General Public License v3.0" + url = "https://www.gnu.org/licenses/gpl-3.0.en.html" + } + } + developers { + developer { + id = "ReVanced" + name = "ReVanced" + email = "contact@revanced.app" + } + } + scm { + connection = "scm:git:git://github.com/revanced/revanced-patches.git" + developerConnection = "scm:git:git@github.com:revanced/revanced-patches.git" + url = "https://github.com/revanced/revanced-patches" + } + } + } + } +} \ No newline at end of file