build: Publish artifacts on Jitpack

This commit is contained in:
oSumAtrIX 2023-10-14 04:38:39 +02:00
parent 03be8522c9
commit 70f93bfadc
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -1,6 +1,9 @@
import org.gradle.kotlin.dsl.support.listFilesOrdered
plugins { plugins {
kotlin("jvm") version "1.8.20" kotlin("jvm") version "1.8.20"
alias(libs.plugins.ksp) alias(libs.plugins.ksp)
`maven-publish`
} }
group = "app.revanced" group = "app.revanced"
@ -27,6 +30,7 @@ dependencies {
implementation(libs.guava) implementation(libs.guava)
// Used in JsonGenerator. // Used in JsonGenerator.
implementation(libs.gson) implementation(libs.gson)
// A dependency to the Android library unfortunately fails the build, which is why this is required. // A dependency to the Android library unfortunately fails the build, which is why this is required.
compileOnly(project("dummy")) compileOnly(project("dummy"))
@ -40,40 +44,74 @@ kotlin {
tasks { tasks {
register<DefaultTask>("generateBundle") { register<DefaultTask>("generateBundle") {
description = "Generate dex files from build and bundle them in the jar file" description = "Generate dex files from build and bundle them in the jar file"
dependsOn(build) dependsOn(build)
doLast { doLast {
val androidHome = System.getenv("ANDROID_HOME") ?: throw GradleException("ANDROID_HOME not found") val d8 = File(System.getenv("ANDROID_HOME")).resolve("build-tools")
val d8 = "${androidHome}/build-tools/33.0.1/d8" .listFilesOrdered().last().resolve("d8").absolutePath
val input = configurations.archives.get().allArtifacts.files.files.first().absolutePath
val work = layout.buildDirectory.dir("libs").get().asFile val artifacts = configurations.archives.get().allArtifacts.files.files.first().absolutePath
val workingDirectory = layout.buildDirectory.dir("libs").get().asFile
exec { exec {
workingDir = work workingDir = workingDirectory
commandLine = listOf(d8, input) commandLine = listOf(d8, artifacts)
} }
exec { exec {
workingDir = work workingDir = workingDirectory
commandLine = listOf("zip", "-u", input, "classes.dex") commandLine = listOf("zip", "-u", artifacts, "classes.dex")
} }
} }
} }
register<JavaExec>("generateMeta") { register<JavaExec>("generateMeta") {
description = "Generate metadata for this bundle" description = "Generate metadata for this bundle"
dependsOn(build) dependsOn(build)
classpath = sourceSets["main"].runtimeClasspath classpath = sourceSets["main"].runtimeClasspath
mainClass.set("app.revanced.meta.PatchesFileGenerator") mainClass.set("app.revanced.meta.PatchesFileGenerator")
} }
// Dummy task to fix the Gradle semantic-release plugin. // Required to run tasks because Gradle semantic-release plugin runs the publish task.
// Remove this if you forked it to support building only. // Tracking: https://github.com/KengoTODA/gradle-semantic-release-plugin/issues/435
// Tracking issue: https://github.com/KengoTODA/gradle-semantic-release-plugin/issues/435 named("publish") {
register<DefaultTask>("publish") { dependsOn("generateBundle")
group = "publish" dependsOn("generateMeta")
description = "Dummy task"
dependsOn(named("generateBundle"), named("generateMeta"))
} }
} }
publishing {
publications {
create<MavenPublication>("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"
}
}
}
}
}