I’ve migrated all my groovy stuff to kotlin, the compiler is happy so far, but at runtime some of my tasks in different subprojects are now failing with this message:
E.g.:
* What went wrong:
Could not determine the dependencies of task ':subproject:assemble'.
> Cannot convert kotlin.Unit to a task.
The following types/formats are supported:
- A String or CharSequence task name or path
- A Task instance
- A TaskReference instance
- A Buildable instance
- A TaskDependency instance
- A Provider that represents a task output
- A Provider instance that returns any of these types
- A Closure instance that returns any of these types
- A Callable instance that returns any of these types
- An Iterable, Collection, Map or array instance that contains any of these types
“–stacktrace” is not helpful either - is there some way to find the explicit location where gradle does have a kotlin.Unit instead of a task now - the project is huge and without a hint it’s somewhat difficult to fix it?
Hard to say from the information you gave.
Somewhere you call a method that historically accepts Object (probably dependsOn in your case), but now with something that returns Unit which cannot be converted to a task.
Now it is building again. Seems I can’t assign that task to a val and use it - obviously as it is failing - although I am not sure why not and why the compiler is happy about that usage.
Yes you can, if you would have, but you didn’t
You assigned the result of calling tasks.cyconledxBom { ... } which is syntactic sugar for tasks.cyconledxBom.configure { ... } which is a void method, so in Kotlin results in Unit, not the task or task provider.
val cycloneDxBom = tasks.cyclonedxBom
cyclonedxBom {
...
}
would have worked.
Or also
val cycloneDxBom by tasks.existing(TypeOfTheTask::class) {
...
}