From d8f99943b4051dc6b8071320061066609924c086 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 13 Dec 2015 09:29:16 -0800 Subject: [PATCH] Document inline tasks. --- documentation/index.html | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/documentation/index.html b/documentation/index.html index 3bf6d97..ec5036b 100644 --- a/documentation/index.html +++ b/documentation/index.html @@ -219,6 +219,30 @@ Our jar file is now declared to be a "fat jar" (which means it will include all The zip directive follows a similar structure, although here we are specifying which file we want to include. For more details on the packaging plug-in, please see its documentation.

+

Inline tasks

+

+ Since Build.kt is a valid Kotlin file, you can write arbitrary Kotlin code in it, + including defining tasks. If you ever need to perform an operation that is not supported by an + existing plug-in and it would be overkill to write a plug-in just for it, you can define that + task directly in your build file, including specifying its run dependencies so that it will + be executed exactly when you want it. Here is an example from TestNG's own build file: +

+
+@Task(name = "createVersion", runBefore = arrayOf("compile"), runAfter = arrayOf("clean"))
+fun taskCreateVersion(project: Project) : TaskResult {
+    val path = "org/testng/internal"
+    with(arrayListOf<String>()) {
+        File("src/main/resources/$path/VersionTemplateJava").forEachLine {
+            add(it.replace("@version@", VERSION))
+        }
+        File("src/generated/java/$path/Version.java").writeText(joinToString("\n"))
+    }
+    return TaskResult()
+}
+

+ This tasks takes a template file and replaces all occurrences of the string "@version@" with the actual version of the project. Obviously, this task is very specific to TestNG's own build and it wasn't worth writing a plug-in ftor this. Note the attributes runBefore and runAfter, which specify when this task will run. You can find more information about tasks in the plug-in development section. +

+

Dependencies