Skip to content

Suppress Warnings in Generated Code with @file:Suppress("REDUNDANT_VISIBILITY_MODIFIER") #459

@leinardi

Description

@leinardi

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 extraWarnings setting 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions