Composite build task execution ordering

hello,
i have a multi-project gradle build (“product”), and a separate stand alone gradle build, which has to be maintained as a separated stand alone build (“stand-alone”).
both projects rely on a generation task that has to be executed prior to their builds.
the project is an application (not android), it uses kotlin, java and maven-publish plugins.

currently, i have the generation task defined in the root project of my “product” build (/build.gradle.kts):

// register generation task
tasks.register<Exec>("gen") {
    doFirst {
       ...
    }
}

tasks {
    "build" {
        dependsOn("gen")
    }
}

subprojects {
 afterEvaluate {
            tasks {
                "processResources" {
                    dependsOn(rootProject.tasks.named("gen"))
                }
            }
        }
}

i tried using the finalizeBy clause to force the included build task to wait on this task:

tasks {
        "gen" {
            finalizedBy(gradle.includedBuild("stand-alone").task(":processResources"))
        }
}

however, in gradle output, i see the “stand-alone”:processResources is executed first in the build.
i’ve read about composite builds in gradle docs (https://docs.gradle.org/current/userguide/composite_builds.html), the example there is the opposite of what i’m looking for.

i’ve also seen references to “preBuild” phase, but as far as i understand, this phase is created by the android plugin, so it’s irrelevant for this case.