Slackbot
01/10/2024, 11:05 PMVampire
01/11/2024, 10:09 AMMartin
01/11/2024, 10:11 AMabstract class MyTask: DefaultTask() {
@get:Input
abstract val myInput: Property<String>
@TaskAction
fun doStuff() { ... }
}Martin
01/11/2024, 10:11 AMMyTask.myInput is not set, it will fail at runtime, I'd like to detect this at build timeMartin
01/11/2024, 10:12 AMVampire
01/11/2024, 10:12 AMMartin
01/11/2024, 10:13 AMMartin
01/11/2024, 10:13 AMVampire
01/11/2024, 10:13 AMMartin
01/11/2024, 10:14 AMclass MyTask(val myInput: Property<String>) : DefaultTask() {
@TaskAction
fun doStuff() { ... }
}
But yea the constructor is not really accessibleVampire
01/11/2024, 10:14 AMVampire
01/11/2024, 10:15 AMMartin
01/11/2024, 10:16 AMhave some extension method that registers the task and has the necessary fields as parameters.That's what I'm doing but that extension method code is the weak link in the chain now because I need to make sure I do not forget any input
Martin
01/11/2024, 10:16 AMAdam
01/11/2024, 11:13 AM@get:Input
val myInput: Property<String> = property(convention = "foo")Adam
01/11/2024, 11:30 AM@get:Input annotations (which are ugly imo) then you could even remove them and register the inputs using the runtime inputs API.Martin
01/11/2024, 11:40 AMMartin
01/11/2024, 11:40 AMMartin
01/11/2024, 11:43 AMProvider that can never be absent or soMartin
01/11/2024, 11:44 AMVampire
01/11/2024, 11:46 AMget() them.
If it is optional you have to check presence or specify a default value to get.Vampire
01/11/2024, 11:46 AMVampire
01/11/2024, 11:47 AMMartin
01/11/2024, 11:47 AMVampire
01/11/2024, 11:48 AMVampire
01/11/2024, 11:48 AMAdam
01/11/2024, 11:49 AMtasks.register(FooTask::class) {
/* properties that you forget to set */
}
you'd want a function with args?
tasks.register(FooTask::class,
a = "a",
)
And then when you add a new b property to FooTask, you'd get an error
tasks.register(FooTask::class,
a = "a",
// error: missing value for arg 'b'
)Martin
01/11/2024, 11:50 AMMartin
01/11/2024, 11:51 AMyou'd want a function with args?This could work but isn't 100% typesafe, is it? All parameters are of
Any type IIRCAdam
01/11/2024, 11:51 AMAdam
01/11/2024, 11:52 AMMartin
01/11/2024, 11:52 AMmanually register tasks is a no-noIt can be hidden behind a DSL method.
Adam
01/11/2024, 11:53 AMMartin
01/11/2024, 11:55 AMmyExtension {
createTask("name", "mandatoryParam", otherTask.flatMap { it.mandatoryRegularFile }, mandatoryIntParam) {
optionalParam.set(...)
}
}Adam
01/11/2024, 11:55 AMVampire
01/11/2024, 11:55 AMMartin
01/11/2024, 11:56 AMMartin
01/11/2024, 11:56 AMAdam
01/11/2024, 12:00 PM@Nested worked properly with recursion and output directories you could create a FooTaskProperties class that had to be manually instantiated and then passed into the FooTask's constructor...ephemient
01/12/2024, 8:30 AMephemient
01/12/2024, 8:31 AM--dry-run will catch missing required inputs, IIRCVampire
01/12/2024, 8:48 AMVampire
01/12/2024, 8:49 AMMartin
01/12/2024, 12:02 PMwithin AGP, task classes have associated creation action classesStuff like this (
CreationAction)? If yes then indeed I'd have to write this manually. Which is doable but error prone.