Skip to content

Commit

Permalink
Add task "shadowJarExecutable" to generate self-running ktlint jar. (#…
Browse files Browse the repository at this point in the history
…515)

This task behaves similar to
https://github.com/brianm/really-executable-jars-maven-plugin
maven plugin - it creates unix runnable file, that executes
ktlint-all.jar without need of additional shell script.

Generated file could be checked by executing
`ktlint/build/run/ktlint --help` command.

Signed-off-by: Yahor Berdnikau <[email protected]>
  • Loading branch information
Tapchicoma authored and shashachu committed Jul 16, 2019
1 parent f2def9a commit cf33468
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ktlint/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit cf33468

Please sign in to comment.