Kotlin 2.2.20 Compiler Warning - GeneratedAppGlideModule
Glide Version: 5.0.4
Associated libraries: Kotlin 2.2.20
Issue details:
Kotlin 2.2.20 introduces a new compiler warning for exposed visibility errors whereby a more visible declaration references a less visible declaration in its signature. This warning is present for GeneratedAppGlideModule. For users with projects configured to treat warnings as errors, this is preventing upgrade to Kotlin 2.2.20. This warning will also become an error in Kotlin version 2.4.
Kotlin documentation: https://youtrack.jetbrains.com/issue/KTLC-271
Compilation warning:
kotlin/com/bumptech/glide/GeneratedAppGlideModuleImpl.kt:11:5 'internal' declaration exposes 'public/*package*/' type 'GeneratedAppGlideModule'. This will become an error in language version 2.4. See https://youtrack.jetbrains.com/issue/KTLC-271.
Here's the hierarchy:
Java public (in library):
package com.bumptech.glide.module;
public abstract class AppGlideModule extends LibraryGlideModule implements AppliesOptions {
Java internal (in library):
package com.bumptech.glide;
/*default*/ abstract class GeneratedAppGlideModule extends AppGlideModule {
Kotlin internal (generated by KSP):
package com.bumptech.glide
internal class GeneratedAppGlideModuleImpl(
@Suppress("UNUSED_PARAMETER")
context: Context,
) : GeneratedAppGlideModule() {
Workaround:
// TODO delete when https://github.com/bumptech/glide/issues/5601 is resolved.
tasks
.named { it == "compileDebugAndroidTestKotlin" }
.configureEach { org.jetbrains.kotlin.gradle.tasks.KotlinCompile task ->
task.compilerOptions.freeCompilerArgs.add("-Xwarning-level=EXPOSED_PACKAGE_PRIVATE_TYPE_FROM_INTERNAL_WARNING:disabled")
}
Change the task name to whatever fails for you. Mine were failing because it's used in tests. Copy the above to the build.gradle of your module. For .kts adjust the lambda syntax a bit. Use :warning if you still want a warning to be shown. This overrides -Werror / allWarningsAsErrors = true setting.
Ref https://kotlinlang.org/docs/compiler-reference.html#xwarning-level
More general workaround that's variant aware:
androidComponents {
onVariants { variant ->
kotlin.target.compilations.named { it == variant.name }.configureEach {
compileTaskProvider.configure {
compilerOptions {
// TODO delete when https://github.com/bumptech/glide/issues/5601 is resolved.
freeCompilerArgs.add("-Xwarning-level=EXPOSED_PACKAGE_PRIVATE_TYPE_FROM_INTERNAL_WARNING:disabled")
}
}
}
}
}
use whatever variant filter you want. variant.unitTest?.name and variant.androidTest?.name can be used to access those source sets.
Asked for help here: https://youtrack.jetbrains.com/issue/KTLC-271/No-exposed-visibility-error-on-internal-class-inheriting-from-package-private-Java-class#focus=Comments-27-12638916.0-0
Thanks for looking into this so quickly. The workaround will get us out of trouble for this release of Kotlin.
I wonder if this is an option as a "solution": https://livefront.com/writing/suppressing-annoying-kotlin-compiler-warnings/ Glide already publishes a KSP, so it might be able to hook into this.
@TWiStErRob I am trying to do this in the root build.gradle.kts but it still fails the build, I have tried your other snippets as well:
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
freeCompilerArgs.addAll(
// TODO delete when https://github.com/bumptech/glide/issues/5601 is resolved.
"-Xwarning-level=EXPOSED_PACKAGE_PRIVATE_TYPE_FROM_INTERNAL_WARNING:disabled"
)
}
}
Kotlin - 2.2.20 KSP - 2.2.20-2.0.4 Glide - 5.0.5
@jaredsburrows I'm not sure what you mean by root. The workaround needs to be applied on the tasks which fail. Check the error message carefully. It'll be most likely on an APK producing module (app or androidTest). If you want to apply it generally standard Gradle convention rules apply. i.e. root build.gradle only configures the : project.