Skip to main content

Top-level API without JvmName

DiagnosticTOP_LEVEL_API_WITHOUT_JVM_NAME
Default severityError
Applies toJVM compilations only
Gradle propertytopLevelApiWithoutJvmName
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.

Health.kt
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​

Network.kt
public fun connect(): Int = 0

Do​

Network.kt
@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 internal callables 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.ExemptionReason
import org.jetbrains.kotlinx.library.api.watchdog.IntentionallyDefaultFacadeName
public 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

See also​