Last active
March 30, 2023 19:46
-
-
Save bowserf/ce6e1d85585aaa610ef060b7f23c433c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fr.bowser.build_src | |
import org.gradle.api.DefaultTask | |
import org.gradle.api.file.DirectoryProperty | |
import org.gradle.api.provider.Property | |
import org.gradle.api.tasks.Input | |
import org.gradle.api.tasks.InputDirectory | |
import org.gradle.api.tasks.OutputDirectory | |
import org.gradle.api.tasks.TaskAction | |
import java.io.File | |
abstract class BundleReleaseFilesTask : DefaultTask() { | |
@get:InputDirectory | |
abstract val rootProject: DirectoryProperty | |
@get:Input | |
abstract val appVersion: Property<String> | |
@get:OutputDirectory | |
abstract val outputDirectory: DirectoryProperty | |
@TaskAction | |
fun run() { | |
check(rootProject.get().asFile.exists()) | |
val buildOutputsDirectory = File(rootProject.get().asFile, "build/outputs") | |
if (!buildOutputsDirectory.exists()) { | |
throw IllegalStateException("File doesn't exist: ${buildOutputsDirectory.absolutePath}") | |
} | |
val resultDirectory = File(outputDirectory.get().asFile, appVersion.get()) | |
if (resultDirectory.exists()) { | |
if (!resultDirectory.deleteRecursively()) { | |
throw IllegalStateException("Output directory deletion failed at path: ${resultDirectory.absolutePath}") | |
} | |
} | |
if (!resultDirectory.mkdirs()) { | |
throw IllegalStateException("Error when creating output directory at path: ${resultDirectory.absolutePath}") | |
} | |
val apkReleaseDirectory = File(buildOutputsDirectory, "apk/release") | |
val apkReleaseFile = apkReleaseDirectory.listFiles().first { it.extension == "apk" } | |
apkReleaseFile.copyTo(File(resultDirectory, apkReleaseFile.name)) | |
val bundleReleaseDirectory = File(buildOutputsDirectory, "bundle/release") | |
val bundleReleaseFile = bundleReleaseDirectory.listFiles().first { it.extension == "aab" } | |
bundleReleaseFile.copyTo(File(resultDirectory, bundleReleaseFile.name)) | |
val mappingReleaseFile = File(buildOutputsDirectory, "mapping/release/mapping.txt") | |
mappingReleaseFile.copyTo(File(resultDirectory, mappingReleaseFile.name)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment