28 septembre 2020

Gradle-Kotlin-DSL:

open class PrintHerokuVersion : Exec() {
    init {
        this.workingDir = project.rootDir
        this.commandLine("/snap/bin/heroku", "-v")
        this.standardOutput = ByteArrayOutputStream()
    }
}

project.tasks.register<PrintHerokuVersion>("printHerokuVersion")

project.tasks.withType<PrintHerokuVersion> {
    doLast { logger.info(standardOutput.toString()) }
}

Pour exécuter la tâche:

$ ./gradlew pHV

Gradle-Groovy-DSL:

task printHerokuVersionGroovy(type: Exec) {
    workingDir(project.projectDir)
    commandLine("/snap/bin/heroku", "-v")
    standardOutput = new ByteArrayOutputStream()
    doLast {
        logger.info(standardOutput.toString())
    }
}

Pour exécuter la tâche:

$ ./gradlew pHVG