How to run execute string as a shell command in Kotlin DSL?

Here’s what it might look like in groovy

def runCommand = { Project project, String command ->
   ByteArrayOutputStream byteOut = new 
   ByteArrayOutputStream() 
   project.exec {
      commandLine = command.split(" ")
      standardOutput = byteOut
   } 
   return new String(byteOut.toByteArray()).trim()
}
def gitBranch = runCommand(project, "git rev-parse --abbrev-ref HEAD") 
def gitTag = runCommand(project, "git tag -l --points-at HEAD") 
def gitCommitId = runCommand(project, "git rev-parse --short=8 HEAD") 
1 Like