Edoardo Luppi
06/05/2025, 4:28 PMdokkaHtmlPartial {
dependsOn(generateKotlinGrammarSource) // ANTLR task
}
in my sub-module build script.
What's the correct task to use in place of dokkaHtmlPartial
for this specific case?Adam Semenenko
06/05/2025, 4:53 PMdependsOn(generateKotlinGrammarSource)
? I suspect the buildscript will have something like tasks.kotlinCompile { dependsOn(generateKotlinGrammarSource) }
...Edoardo Luppi
06/05/2025, 4:54 PMI guess it generates Kotlin source code?Correct! The entire snippet is
withType<KotlinCompilationTask<*>>().configureEach {
dependsOn(generateKotlinGrammarSource)
}
dokkaHtmlPartial {
dependsOn(generateKotlinGrammarSource)
}
//
// The source JAR tasks must explicitly depend on the grammar generation
// to avoid Gradle complaining and erroring out
//
sourcesJar {
dependsOn(generateKotlinGrammarSource)
}
kotlin.targets.configureEach {
if (publishable) {
named<Jar>("${targetName}SourcesJar") {
dependsOn(generateKotlinGrammarSource)
}
}
}
Adam Semenenko
06/05/2025, 4:57 PMdependsOn()
so Gradle can infer the task dependencies properly.
Replace
dokkaHtmlPartial {
dependsOn(generateKotlinGrammarSource) // ANTLR task
}
with
tasks.withType(org.jetbrains.dokka.gradle.tasks.DokkaGenerateTask.java).configureEach {
dependsOn(generateKotlinGrammarSource)
}
(my Groovy is very underdeveloped so you might need to fix something)Adam Semenenko
06/05/2025, 5:04 PM@OutputDirectory
, then it should be as simple as this:
kotlin {
sourceSets {
main {
kotlin.srcDir(generateKotlinGrammarSource)
}
}
}
Gradle will then recognise it needs to run the task to generate the source code, and all the task dependencies will be inferred automatically.Edoardo Luppi
06/05/2025, 5:05 PMkotlin {
sourceSets {
commonMain {
kotlin {
srcDir(layout.buildDirectory.dir("generatedAntlr"))
}
...
But Gradle didn't like it anyway at the time I set it up (1.9.24). Not sure if something has changed in the meantime.Adam Semenenko
06/05/2025, 5:07 PMkotlin {
sourceSets {
commonMain {
kotlin {
srcDir(generateKotlinGrammarSource)
}
...
Edoardo Luppi
06/05/2025, 5:09 PMdependsOn
from KotlinCompilationTask
and DokkaGenerateTask
?Adam Semenenko
06/05/2025, 5:09 PMEdoardo Luppi
06/05/2025, 5:10 PM@OutputDirectory
that Gradle infers it automatically?Adam Semenenko
06/05/2025, 5:10 PMEdoardo Luppi
06/05/2025, 5:10 PMAdam Semenenko
06/05/2025, 5:10 PMEdoardo Luppi
06/05/2025, 5:12 PMsourcesJar
and kotlin.targets
.Edoardo Luppi
06/05/2025, 5:14 PMEdoardo Luppi
06/05/2025, 5:16 PMAdam Semenenko
06/05/2025, 5:16 PM