Suppress Warnings in Generated Code with `@file:Suppress("REDUNDANT_VISIBILITY_MODIFIER")`
When using Kotlin Inject in a project configured with stricter compiler options, such as:
tasks.withType<KotlinCompilationTask<*>>().configureEach {
compilerOptions {
extraWarnings.set(true)
}
}
The following warning is generated for Kotlin Inject-generated code:
w: file:///path/to/generated/file.kt:line:column Redundant visibility modifier.
This warning appears because the generated code includes unnecessary visibility modifiers, which the stricter compiler options flag as redundant.
Proposed Solution
Add the annotation @file:Suppress("REDUNDANT_VISIBILITY_MODIFIER") at the top of each generated file to suppress this specific warning in generated code.
This change would prevent these warnings from appearing when stricter compiler options like extraWarnings.set(true) are enabled, while not impacting other aspects of the generated code or its functionality.
Example: Generated Code with Suppression
Here’s an example of how the annotation could be included in a generated file:
@file:Suppress("REDUNDANT_VISIBILITY_MODIFIER")
package com.example.generated
public class InjectAppComponent {
// Generated code here...
}
Benefits
- Keeps the project clean and free of compiler warnings, especially in projects using stricter compiler configurations.
- Does not require developers to modify generated files manually or disable the
extraWarningssetting for the entire project.
This small change will improve developer experience by ensuring Kotlin Inject-generated code does not cause unnecessary warnings in projects with stricter compiler settings.
I attempted to add suppression annotations before but couldn't get them to work, PR welcoming if you can get this to work https://github.com/evant/kotlin-inject/issues/267#issuecomment-1694583588
As a more minor note your issue description is overly verbose. Would be quicker and easier to understand without the extra fluff.
I attempted to add suppression annotations before but couldn't get them to work, PR welcoming if you can get this to work #267 (comment)
Sure, I'll give it a try after the holidays.
As a more minor note your issue description is overly verbose. Would be quicker and easier to understand without the extra fluff.
I'll keep it in mind for the next time.
@evant PR created: #460