diff --git a/ktlint/build.gradle b/ktlint/build.gradle index cc5de307eb..1503785313 100644 --- a/ktlint/build.gradle +++ b/ktlint/build.gradle @@ -44,3 +44,22 @@ dependencies { testImplementation deps.junit testImplementation deps.assertj } + +// Implements https://github.com/brianm/really-executable-jars-maven-plugin maven plugin behaviour. +// To check details how it works, see http://skife.org/java/unix/2011/06/20/really_executable_jars.html. +tasks.register("shadowJarExecutable", DefaultTask.class) { + description = "Creates self-executable file, that runs generated shadow jar" + group = "Distribution" + + inputs.files tasks.named("shadowJar") + outputs.file "$buildDir/run/ktlint" + + doLast { + File execFile = outputs.files.singleFile + execFile.withOutputStream { + it.write "#!/bin/sh\n\nexec java -Xmx512m -jar \"\$0\" \"\$@\"\n\n".bytes + it.write inputs.files.singleFile.bytes + } + execFile.setExecutable(true, false) + } +}