Skip to main content

DSL markers with no-op targets

DiagnosticDSL_MARKER_NOOP_TARGET
Default severityError
Gradle propertydslMarkerNoopTarget
Exemption@IntentionallyWrongDslMarkerTargetsForBackwardsCompatibility

What it reports​

Each explicit @Target entry on a @DslMarker annotation outside this set:

  • CLASS.
  • ANNOTATION_CLASS.
  • TYPE.
  • TYPEALIAS.
@DslMarker
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
public annotation class MyDsl

Rationale​

DSL scope control ignores markers on functions and properties. Such targets let callers apply markers that don't restrict outer receivers.

Don't​

// This is the shape that broke Ktor's @KtorDsl (KTOR-8901).
@DslMarker
@Target(
AnnotationTarget.CLASS,
AnnotationTarget.TYPEALIAS,
AnnotationTarget.TYPE,
AnnotationTarget.FUNCTION,
)
public annotation class KtorDsl

Do​

@DslMarker
@Target(
AnnotationTarget.CLASS,
AnnotationTarget.TYPE,
AnnotationTarget.TYPEALIAS,
)
public annotation class KtorDsl

Notes​

Exemption​

If this is intended, apply @IntentionallyWrongDslMarkerTargetsForBackwardsCompatibility to the DSL marker.

Use the exemption if a narrower target set on a published marker rejects existing user code:

@IntentionallyWrongDslMarkerTargetsForBackwardsCompatibility
@DslMarker
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
public annotation class KtorDsl

The annotation doesn't have a reason parameter. Its description is optional.

Configuration​

build.gradle.kts
apiWatchdog {
dslMarkerNoopTarget = WatchdogSeverity.ERROR
}

For a direct compiler call:

-P plugin:org.jetbrains.kotlinx.library.api.watchdog:diagnosticSeverity=DSL_MARKER_NOOP_TARGET:error

See also​