Top-level API without JvmName
| Diagnostic | TOP_LEVEL_API_WITHOUT_JVM_NAME |
| Default severity | Error |
| Applies to | JVM compilations only |
| Gradle property | topLevelApiWithoutJvmName |
| Exemption | @IntentionallyDefaultFacadeName |
What it reports
Files without @file:JvmName that have a Java-visible top-level function or property in the
public API or declared as @PublishedApi internal. The check reports one diagnostic for each file.
public fun ping(): Int = 0
Rationale
Without @file:JvmName, the facade name depends on the file name. A file rename breaks
Java source calls and existing binaries that reference the facade.
Don't
public fun connect(): Int = 0
Do
@file:JvmName("Network")public fun connect(): Int = 0
Notes
- The check skips files with only classes, objects, or type aliases.
- The check skips files without a Java-visible top-level callable.
- The check includes
@PublishedApi internalcallables because public inline bodies can copy facade references into user binaries.
Exemption
If this is intended, apply @file:IntentionallyDefaultFacadeName to the file.
Use the exemption when the declaration is part of the API design or must stay for backwards compatibility.
@file:IntentionallyDefaultFacadeName(reason = ExemptionReason.FOR_BACKWARDS_COMPATIBILITY,)import org.jetbrains.kotlinx.library.api.watchdog.ExemptionReasonimport org.jetbrains.kotlinx.library.api.watchdog.IntentionallyDefaultFacadeNamepublic fun connect(): Int = 0
Configuration
build.gradle.kts
apiWatchdog {javaInterop {topLevelApiWithoutJvmName = WatchdogSeverity.ERROR}}
javaInterop { enabled = false } disables all Java interop checks.
For a direct compiler call:
-P plugin:org.jetbrains.kotlinx.library.api.watchdog:diagnosticSeverity=TOP_LEVEL_API_WITHOUT_JVM_NAME:error