Colton Idle
11/14/2025, 7:23 PMsubprojects {
configurations.configureEach {
resolutionStrategy ...
}
afterEvaluate { subproject ->
subproject.apply from: "$subproject.rootDir/jacocoTask.gradle"
}
}
I updated the after evaluate in kts to
afterEvaluate {
apply { from("$rootDir/jacocoTask.gradle") }
}
but now I get an error in my jacocoTask.gradle file on this line
task coverageReport(type: JacocoReport...
So my questions are:
1. Is my conversion correct?
2. I'm assuming the previous code was not correct since I now get an error in my jacoco Task.gradle file? I guess it wasn't being executed at all before? 😱
I'm new to this project so its been ad adventure trying to modernize some of these things 😅Colton Idle
11/14/2025, 8:38 PMVampire
11/14/2025, 10:37 PMsubproject.rootdir and rootdir should be the same.
It should always be the project directory of the root project of the build.
But that the original little snippet combines at least 4 quite bad practices you know, right? 🙂Vampire
11/14/2025, 10:39 PMjacocoTAsk.gradle, because the snippet you showed is syntactically not valid Kotlin, so the build script would not even compile 🙂Colton Idle
11/15/2025, 1:00 AMsubprojects because I should be using convention plugins I think? 😅 (please let me know what other cardinal rules im breaking here. always learning.
And yes sorry about the kts compile issue. I updated the snippet. I dont have gradle slack on my work laptop. sorry for the sloppy copy pasta.ephemient
11/15/2025, 1:02 AMapplyephemient
11/15/2025, 1:03 AMapply(from =) because apply {} is Kotlin's receiver and not Gradle's plugin applicationColton Idle
11/15/2025, 1:08 AMColton Idle
11/15/2025, 1:09 AMafterEvaluate { subproject ->
subproject.apply from: "$subproject.rootDir/jacocoTask.gradle"
}
while (keeping it in groovy)
afterEvaluate {
apply from: "$rootDir/jacocoTask.gradle"
}
does cause an error downstream...Colton Idle
11/15/2025, 1:10 AMephemient
11/15/2025, 1:14 AMapply which takes a closure, https://docs.gradle.org/current/kotlin-dsl/gradle/org.gradle.api.plugins/-plugin-aware/apply.htmlephemient
11/15/2025, 1:14 AMColton Idle
11/15/2025, 1:35 AMVampire
11/15/2025, 8:40 AMThe only one I can think of is subprojects because I should be using convention plugins I think? 😅 (please let me know what other cardinal rules im breaking here. always learning.
Yes, cross-project configuration is one of the points. Next is
afterEvaluate which should imho be avoided at almost any cost and die the most part only brings you ordering problems, timing problems, and race conditions.
Then using a legacy script plugin (the ones you use with "apply from", they have many works and are discouraged.
And number 4 is task coverageReport(type: JacocoReport... which is an eager API, directly creating the task, instead of a lazy API leveraging task-configuration avoidance.
Regarding the actual question, I think the problem was already started (wrong apply), but I wonder what from is used there then.
JaCoCo works fine with Kotlin, yes, I use it every day.Colton Idle
11/15/2025, 9:04 AMafterEvaluate { subproject ->
subproject.apply from: "$subproject.rootDir/jacocoTask.gradle"
}
after build.gralde (not kts)
afterEvaluate {
apply from: "$rootDir/jacocoTask.gradle"
}
and it does cause an error downstream...
so even without moving to kts, I still have the same error so it seems like subproject is actually needed?Colton Idle
11/15/2025, 9:10 AMafterEvaluate {
it.apply from: "$rootDir/jacocoTask.gradle"
}
then no failure...Colton Idle
11/15/2025, 9:13 AMit to this. then no failure again. this hurts my brain.Vampire
11/15/2025, 10:29 AMapply { from("$rootDir/jacocoTask.gradle") } that @ephemient and me thought is invalid is fine.
apply is void apply(Action<? super ObjectConfigurationAction> action);.
TIL
so even without moving to kts, I still have the same error so it seems like subproject is actually needed?Without looking, I guess without the
subproject. you call it on the cross-configuring project when the cross-configured projectg is configued.
So you apply that script plugin to the root project or whereever the code is instead of the subproject.
okay. very interesting. so if I do (build.gradle, still no kts)Yes, what I just said. if you leave out the
subproject ->, then it is it.
and if i convert the above to kts... then i get a failure... until I changeThat's because of the sam-with-receiver plugin, so that in that lambda the argument is available astoit. then no failure again. this hurts my brain.this
this, so that you can have a nicer DSL.
But that is a Kotlin specific and in Groovy it is different.Colton Idle
11/15/2025, 6:34 PMVampire
11/15/2025, 9:50 PMsubprojects { ... }, you do the closure two times, once for each subproject.
And as you call the apply on the root project, you call it twice in the root project.
And as it is a legacy script plugin, not a normal plugin, it is indeed done twice, so on second indication the task is already registered and it fails.Colton Idle
11/16/2025, 5:14 AM