Kotlin DSL Equivalent for Task Output Directory

I am trying to use the Jooq Generator Plugin with the Kotlin DSL. In the examples for groovy syntax, there is the block

sourceSets.main.java.srcDirs (
    tasks.named('generateFirstJooq').flatMap { it.outputDir },
    tasks.named('generateSecondJooq').flatMap { it.outputDir }

I was trying to re-write this in Kotlin, but I can’t seem to access the outputDir property. Does anyone know what the equivalent syntax would be in the Kotlin DSL?

This is the link to the full build.gradle file: gradle-jooq-plugin/build.gradle at main · etiennestuder/gradle-jooq-plugin · GitHub


Groovy is duck-typed, Kotlin is strongly typed.
With tasks.named('generateFirstJooq') you just get a generic Task to work with.
Use tasks.named<TheTypOfTheTask>('generateFirstJooq') and you have the correct type to work with and get the property from.

Ah…I had tried

tasks.named("generateFirstJooq").flatMap {
  // code here  

but wasn’t parameterizing with the type. Thank you!

1 Like