hfhbd
01/06/2025, 4:35 PMhfhbd
01/06/2025, 4:36 PMval s = tasks.named("myCustomTask")
kotlin.target.compilations.register("foo") {
kotlinSourceSets.forAll {
it.kotlin.srcDir(s)
}
}
If I run: compileFooKotlin
, the task myCustomTask
won't be executed.Javier
01/06/2025, 4:56 PMhfhbd
01/06/2025, 5:42 PMkotlin.target.compilations.register("foo") {
defaultSourceSet {
kotlin.srcDir(s)
}
}
Does not execute the task, but creating a Java feature does (compileBarKotlin
):
val bar by sourceSets.registering {
kotlin.srcDir(s)
}
java.registerFeature("bar") {
usingSourceSet(bar.get())
}
Albert Chang
01/07/2025, 2:34 AMsrcDir
?
I used this code to add generated source to commonMain
, and it worked.
val kotlinSourceDir = project.files(task.map { it.generatedSrcMainDirectory }).builtBy(task)
extensions.getByType(KotlinMultiplatformExtension::class).sourceSets["commonMain"].kotlin.srcDir(kotlinSourceDir)
(task.generatedSrcMainDirectory
is an @Output
of task
.)Javier
01/07/2025, 3:43 AMAlbert Chang
01/07/2025, 3:50 AMhfhbd
01/07/2025, 7:29 AMmbonnin
01/07/2025, 10:11 AMhfhbd
01/07/2025, 10:23 AMmbonnin
01/07/2025, 10:27 AMmbonnin
01/07/2025, 10:28 AMJavier
01/07/2025, 10:35 AM./gradlew jvmFooClasses --dry-run
Shows
:kotlin-stdlib:checkKotlinGradlePluginConfigurationErrors SKIPPED
:kotlin-stdlib:compileKotlinJvm SKIPPED
:kotlin-stdlib:jvmProcessResources SKIPPED
:kotlin-stdlib:jvmMainClasses SKIPPED
:kotlin-stdlib:random SKIPPED
:kotlin-stdlib:compileFooKotlinJvm SKIPPED
:kotlin-stdlib:jvmFooProcessResources SKIPPED
:kotlin-stdlib:jvmFooClasses SKIPPED
random
is executed, so using implementation
+ getting the output files from the task does the trick.Javier
01/07/2025, 10:37 AMimplementation
+ adding directly the task does not work (you need to call map
and get the files manually). IMO, it should be possible, so probably it could be a feature request for Gradle.mbonnin
01/07/2025, 10:41 AMgetting the output files from the task does the trickI'm guessing the output files are source files, not class files?
Javier
01/07/2025, 10:41 AMmbonnin
01/07/2025, 10:42 AMimplementation
is adding files to the compile classpath of the compiler, not to the source filesmbonnin
01/07/2025, 10:42 AM*.kt
in implementation
, not sure if the Kotlin compiler is going to like itJavier
01/07/2025, 10:43 AMhfhbd
01/07/2025, 11:41 AMval outputFolder = layout.buildDirectory.dir("a")
val t = tasks.register("a") {
outputs.dir(outputFolder)
doLast {
outputFolder.get().file("foo.kt").asFile.writeText(
"invalid code to fail compilation"
)
}
}
kotlin.target.compilations.register("foo") {
defaultSourceSet {
dependencies {
implementation(t.map { it.outputs.files })
}
}
}
Javier
01/07/2025, 11:43 AMhfhbd
01/07/2025, 11:57 AM--info
hfhbd
01/07/2025, 11:57 AM