Compiling generated Java sources

Hello!

I got stuck with a problem, which I could not solve on my own, although it does not seem to be very exotic. I have tried solutions based on the docs and the suggested topics here, but could not get them to work.

Gradle version 6.0.1, Kotlin-DSL, multi module Java project with a Gradle plugin defined in buildSrc/. The plugin executes a task srcgen, which generates a Java source file in a submodule and writes it to build/generated/sources/srcgen/com/clemens/utils/Helper.java.

In the submodule’s build.gradle.kts, I have:


[...]

val compileJava by tasks
val srcgen by tasks
gradle.projectsEvaluated {
    compileJava.dependsOn(srcgen)
}

java {
    sourceSets["main"].java {
        "build/generated/sources/srcgen"
    }
}

[...]

The task srcgen is executed before compilation and the file is generated in the submodule as build/generated/sources/srcgen/com/clemens/utils/Helper.java. Thus, the source code generation works. But the compile task does not succeed, because the generated class/package cannot be found.

It seems, that I am missing something crucial. Hints are appreciated!

Clemens

Just solved it, I really missed something.

I had to replace

java {
    sourceSets["main"].java {
        "build/generated/sources/srcgen"
    }
}

by

java {
    sourceSets["main"].java {
        srcDir("build/generated/sources/srcgen")
    }
}

The change is the srcDir(...) constructor.

I tried quite long, and just after posting and rereading a topic for the n-th time, I found this detail. I apologize …