diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 166b1d2..599c0a7 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,14 +1,3 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Java application project to get you started. - * For more details on building Java & JVM projects, please refer - * to https://docs.gradle.org/8.14/userguide/building_java_projects.html in the Gradle documentation. - */ - -import org.gradle.api.tasks.TaskAction -import org.gradle.api.DefaultTask - plugins { // Apply the application plugin to add support for building a CLI application in Java. application @@ -70,29 +59,15 @@ tasks.jar { duplicatesStrategy = DuplicatesStrategy.EXCLUDE } -// Custom task to create a shell script wrapper compatible with bash and zsh -abstract class CreateShellScriptTask : DefaultTask() { - @get:OutputFile - abstract val outputFile: Property - - @TaskAction - fun createScript() { - outputFile.get().writeText( - """ - |#!/bin/sh - |DIR="$(cd "$(dirname "$0")" && pwd)" - |exec java -jar "${'$'}DIR/bounding-box.jar" "${'$'}@" - """.trimMargin() - ) - outputFile.get().setExecutable(true) - } +tasks.register("createShellScript") { + outputFile.set(layout.buildDirectory.file("libs/bounding-box")) + outputs.upToDateWhen { false } } -tasks.register("createShellScript") { - outputFile.set(layout.buildDirectory.file("libs/bounding-box").map { it.asFile }) +tasks.named("createShellScript") { + mustRunAfter("test") } -// Ensure the shell script is created after the JAR tasks.build { dependsOn("createShellScript") } \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..b22ed73 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/CreateShellScriptTask.kt b/buildSrc/src/main/kotlin/CreateShellScriptTask.kt new file mode 100644 index 0000000..c9b8700 --- /dev/null +++ b/buildSrc/src/main/kotlin/CreateShellScriptTask.kt @@ -0,0 +1,24 @@ +import org.gradle.api.DefaultTask +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction +import java.io.File + +abstract class CreateShellScriptTask : DefaultTask() { + @get:OutputFile + abstract val outputFile: RegularFileProperty + + @TaskAction + fun createScript() { + val file = outputFile.get().asFile + file.writeText( + """ + |#!/bin/sh + |DIR="$(cd "$(dirname "$0")" && pwd)" + |exec java -jar "${'$'}DIR/bounding-box.jar" "${'$'}@" + """.trimMargin() + ) + file.setExecutable(true) + logger.lifecycle("Shell script created at: ${file.absolutePath}") + } +} \ No newline at end of file