https://kotlinlang.org logo
Title
t

tieskedh

11/19/2020, 8:45 PM
I've an question. I have a gradle-plugin that generates some code. However, Kotlin doesn't seem to find the code during compilation... I'm using Multiplatform, is there something I'm missing?
class PropsToObjectPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        val extension: PropsToObjectExtension = target
            .extensions
            .create("propsToObject")

        val buildDir = target.file(
            "${target.buildDir}/generated/source/props"
        )

        val taskProvider = target.tasks
            .register<PropertyObjectGeneratingTask>(
                "generatePropertyObject"
            ) {
                fileName = target.file(extension.propFileName)
                this.genDir = buildDir
            }

        target.tasks.withType<KotlinCompile> {
            //<https://youtrack.jetbrains.com/issue/KT-42241>
            val srcTask = this as SourceTask
            srcTask.dependsOn(taskProvider)
            val srcSet = target
                .objects
                .sourceDirectorySet("nl.devhaan.props", "generatedPropertyObject")
                .srcDir(buildDir)
            srcTask.source(srcSet)
        }
    }
}
b

Big Chungus

11/19/2020, 10:25 PM
You need to register generated dir as kotlin or java sources
t

tieskedh

11/20/2020, 8:19 AM
sorry for the late reaction... The sources I generate will always live in commonMain. How do I register it as Kotlin-sources? I thought
srcTask.source
would registrate it? The code itself is imported by Intellij, so the autocompletion works, just the compilation fails.