Status Update
Comments
ra...@google.com <ra...@google.com>
sp...@google.com <sp...@google.com>
sp...@google.com <sp...@google.com> #2
I have a pending fix for this.
Are you currently setting the jvmTarget
on the KotlinCompile
tasks in an afterEvaluate
block? In my repro project, I was able to work around the issue by setting it inside an afterEvaluate
block... not sure if that will work for you too, but maybe worth a try.
za...@gmail.com <za...@gmail.com> #3
We aren't, we do a tasks.withType(...).configureEach callback:
sp...@google.com <sp...@google.com> #4
A workaround might be to put the project.tasks.configureKotlinCompilationTask
call inside a project.afterEvaluate
block.
za...@gmail.com <za...@gmail.com> #5
I'll give it a try, though that has me worried it'll stay racy if we try that
za...@gmail.com <za...@gmail.com> #6
That appears to be working 👍
za...@gmail.com <za...@gmail.com> #8
Re: the workaround
I think the workaround incurs another issue. I haven't been able to find exactly where because it's so annoying to debug configuration internals in gradle, but I think there is somewhere where AGP is setting a provider value on kapt stub gen KotlinCompile tasks with
I've attempted to implement the workaround here:
* What went wrong:
Execution failed for task ':libraries:telemetry:telemetry-internal:kaptGenerateStubsReleaseKotlin'.
> Error while evaluating property 'disableMultiModuleIC' of task ':libraries:telemetry:telemetry-internal:kaptGenerateStubsReleaseKotlin'.
> Cannot query the value of property 'freeCompilerArgs' because it has no value available.
...
Caused by: org.gradle.api.internal.provider.MissingValueException: Cannot query the value of property 'freeCompilerArgs' because it has no value available.
at org.gradle.api.internal.provider.AbstractMinimalProvider.calculateOwnPresentValue(AbstractMinimalProvider.java:82)
at org.gradle.api.internal.provider.AbstractMinimalProvider.get(AbstractMinimalProvider.java:100)
at org.jetbrains.kotlin.gradle.internal.KaptGenerateStubsTask.isIncrementalCompilationEnabled$kotlin_gradle_plugin_common(KaptGenerateStubsTask.kt:163)
at org.jetbrains.kotlin.gradle.internal.KaptGenerateStubsTask_Decorated.isIncrementalCompilationEnabled$kotlin_gradle_plugin_common(Unknown Source)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile$disableMultiModuleIC$2.invoke(KotlinCompile.kt:395)
at org.jetbrains.kotlin.gradle.tasks.KotlinCompile$disableMultiModuleIC$2.invoke(KotlinCompile.kt:394)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
sp...@google.com <sp...@google.com> #9
Any ideas?
I don't see anywhere in the AGP codebase where we're setting the freeCompilerArgs
with a provider.
I've attempted to implement the workaround here:
https://github.com/slackhq/slack-gradle-plugin/pull/957
I see the following code in that link: freeCompilerArgs.addAll(slackProperties.kotlinJvmFreeArgs)
and some other calls to freeCompilerArgs.addAll()
too. Could any of those be causing the error?
an...@google.com <an...@google.com> #10
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
- Android Studio Ladybug Feature Drop | 2024.2.2 Canary 2
- Android Gradle Plugin 8.8.0-alpha02
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Thank you for taking the time to submit feedback — we really appreciate it!
ju...@yahooinc.com <ju...@yahooinc.com> #11
sp...@google.com <sp...@google.com> #12
Was a resolution ever found to the MissingValueException? I am seeing the same issue
Not that I know of.
Are you hitting that after trying the workaround from #4?
If so, does using AGP 8.8.0-alpha02 or newer fix the original problem for you?
ju...@yahooinc.com <ju...@yahooinc.com> #13
Are you hitting that after trying the workaround from #4?
No, I am seeing the issue from #8 without having hit the original issue. I've been attempting to debug myself, but as the original reporter said, it can be frustrating to debug configuration internals in gradle.
However I have managed to work around it. As the original reporter said, I believe there is somewhere where AGP is setting a provider value on kapt stub gen KotlinCompile tasks with
I acknowledge that you were unable to find a location where this occurs, so possible this is being performed in kapt library. But the project I am working on uses freeCompilerArgs minimally, and I don't believe we are causing this ourselves.
Avoid the e via the following setup in the applicable areas where freeCompilerArgs are being set (simplified for sharing purposes):
android {
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
try {
freeCompilerArgs.appendAll(
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
)
} catch (e: MissingValueException) {
freeCompilerArgs.set(mutableListOf())
freeCompilerArgs.appendAll(
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
)
}
}
}
}
sp...@google.com <sp...@google.com> #14
Thanks for the info!
If you use AGP 8.8.0-alpha02 or newer, do you still need the workaround in #13?
ju...@yahooinc.com <ju...@yahooinc.com> #15
sp...@google.com <sp...@google.com> #16
Thanks for the info. Any chance you can create a repro project hitting the MissingValueException
? I wasn't able to repro it on my side previously.
ju...@yahooinc.com <ju...@yahooinc.com> #17
Any chance you can create a repro project hitting the MissingValueException? I wasn't able to repro it on my side previously.
Apologies, this would not be something I would have the chance to do with my current workload.
I did note though, that when swapping freeCompilerArgs.append/appendAll
for freeCompilerArgs.add/addAll
the failure re-emerged. This is of interest to me since append* gets removed in Gradle 8.8:
ju...@yahooinc.com <ju...@yahooinc.com> #18
Update:
The issue did lie in our usage of freeCompilerArgs
. Traced the issue back to the following format in root build.gradle.kts
. This setup had worked prior to upgrading to 2.0.0. Was able to work around the issue once I was aware of what caused it.
subprojects {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
compilerOptions {
freeCompilerArgs.add(*any arg here*)
}
}
}
You should be able to reproduce now with this setup in any project.
sp...@google.com <sp...@google.com> #19
Thanks for the update! I filed
Description
I've been trying out kotlin test fixtures in AGP 8.5 was surprised to find that classes compiled by these tasks were using the jvm-target of our running JDK (22) in our case, and not the one our convention plugin sets for all KotlinCompile tasks (17).
After some digging and disallowChanges use to track down who was overriding this, it looks like AGP sources kotlinOptions from
android.kotlinOptions
? tbh I didn't realize this DSL still existed, and kinda wonder why. Is this intentional? Confirmed that if I manually set these values separately, it works as expected.Could these be deduped (or at least source from the same convention as other KGP tasks?). The reason I ask is because this means to use testFixtures, our convention plugin would have to add a separate, somewhat duplicate code path to configure kotlin options just for AGP test fixtures that uses legacy APIs (i.e.
kotlinOptions
and not the new property-basedcompilerOptions
).