Markus Fung
07/21/2023, 4:58 AMPoisonedYouth
07/21/2023, 5:13 AMMarkus Fung
07/21/2023, 5:46 AMAdam S
07/21/2023, 6:10 AMMarkus Fung
07/21/2023, 6:23 AMMarkus Fung
07/21/2023, 6:24 AMMarkus Fung
07/21/2023, 6:24 AMAdam S
07/21/2023, 6:25 AMMarkus Fung
07/21/2023, 6:25 AMAdam S
07/21/2023, 6:25 AMAdam S
07/21/2023, 6:28 AMAdam S
07/21/2023, 6:30 AMAdam S
07/21/2023, 6:33 AMMarkus Fung
07/21/2023, 6:33 AMMarkus Fung
07/21/2023, 6:33 AMAdam S
07/21/2023, 6:33 AMthanks for your answer but im still not fully clear about it.that makes sense, Gradle is really confusing :) Keep asking questions!
Markus Fung
07/21/2023, 6:34 AMMarkus Fung
07/21/2023, 6:34 AMMarkus Fung
07/21/2023, 6:35 AMtasks.register("TemplateExampleTask") {
// do something
}
Adam S
07/21/2023, 6:39 AMtasks.register("TemplateExampleTask")
will create a task with the name of TemplateExampleTask
, but the type won’t have a type of class TemplateExampleTask
To register a task with the type TemplateExampleTask
, you need to specify the task
import com.ncorti.kotlin.gradle.template.plugin.TemplateExampleTask
tasks.register<TemplateExampleTask>("TemplateExampleTask")
(btw, it’s usually good to use tasks.register
👍)Adam S
07/21/2023, 6:42 AMprintln()
to see what happens:
tasks.register("myPhaseExampleTask") {
println("this will be printed in phase 2, the configuration phase")
doLast {
println("this will be printed in phase 3, the execution phase")
}
}
if you run ./gradlew myPhaseExampleTask
then you’ll see both lines printed.
But if you run a different task, like ./gradlew help
, then you’ll only see the phase 2
line printed - because the myPhaseExampleTask
task isn’t executedMarkus Fung
07/21/2023, 6:43 AMMarkus Fung
07/21/2023, 6:43 AMMarkus Fung
07/21/2023, 6:44 AMMarkus Fung
07/21/2023, 6:44 AMAdam S
07/21/2023, 6:45 AMAdam S
07/21/2023, 6:47 AMMarkus Fung
07/21/2023, 6:47 AMMarkus Fung
07/21/2023, 6:47 AMAdam S
07/21/2023, 6:47 AMMarkus Fung
07/21/2023, 6:49 AMtasks.register<TemplateExampleTask>("TemplateExampleTask")
and defining it in a plugin and then apply the pluginMarkus Fung
07/21/2023, 6:49 AMAdam S
07/21/2023, 6:49 AMAdam S
07/21/2023, 6:56 AMMarkus Fung
07/21/2023, 7:02 AMMarkus Fung
07/21/2023, 7:03 AMMarkus Fung
07/21/2023, 7:03 AMdoLast
Markus Fung
07/21/2023, 7:04 AMMarkus Fung
07/21/2023, 7:04 AMMarkus Fung
07/21/2023, 7:04 AMAdam S
07/21/2023, 7:07 AMAdam S
07/21/2023, 7:08 AMMarkus Fung
07/21/2023, 7:08 AMMarkus Fung
07/21/2023, 7:09 AMAdam S
07/21/2023, 7:10 AMMarkus Fung
07/21/2023, 7:10 AMMarkus Fung
07/21/2023, 7:11 AMAdam S
07/21/2023, 7:11 AMAdam S
07/21/2023, 7:12 AMMarkus Fung
07/21/2023, 7:14 AMAdam S
07/21/2023, 7:14 AMMarkus Fung
07/21/2023, 7:18 AMkotlin-dsl-precompiled-script-plugins
Adam S
07/21/2023, 7:21 AMMarkus Fung
07/21/2023, 7:23 AMkotlin-dsl
, it already included kotlin-dsl-precompiled-script-plugins
?Adam S
07/21/2023, 7:23 AMMarkus Fung
07/21/2023, 7:24 AMMarkus Fung
07/21/2023, 7:24 AMAdam S
07/21/2023, 7:24 AMTheplugin.kotlin-dsl
• Applies thepluginjava-gradle-plugin
• Applies thepluginkotlin-dsl.base
• Applies thepluginkotlin-dsl.precompiled-script-plugins
Markus Fung
07/21/2023, 7:26 AMkotlin-dsl-precompiled-script-plugins
Adam S
07/21/2023, 7:27 AMMarkus Fung
07/21/2023, 7:28 AMAdam S
07/21/2023, 7:29 AMVampire
07/21/2023, 8:53 AMif you have any more questions then fire away, or you can ask in the Gradle Slack too (the link is in the channel description)The "or you can" should actually be "but you should" and "too" removed. This thread is off-topic, as this channel is only for Kotlin-specific Gradle question like using Kotlin in Gradle build scripts or using the Kotlin Gradle Plugin, not for general Gradle questions. 😉 Also, speaking about idiomaticness, tasks are the "work doers" but should not have opinion to increase reuse. Same for extensions. Plugins then add opinon by adding extensions, registering tasks, wiring extension properties and task properties together and setting default values.