Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 5 additions & 30 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<File>

@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<CreateShellScriptTask>("createShellScript") {
outputFile.set(layout.buildDirectory.file("libs/bounding-box"))
outputs.upToDateWhen { false }
}

tasks.register<CreateShellScriptTask>("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")
}
7 changes: 7 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
}
24 changes: 24 additions & 0 deletions buildSrc/src/main/kotlin/CreateShellScriptTask.kt
Original file line number Diff line number Diff line change
@@ -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}")
}
}