
Compiler plugin inserting simple or qualified class names at compile time, preserving names across obfuscation and working in environments where reflection lacks qualified names; supports inline reified wrappers.
Kompile-time names is a Kotlin Multiplatform compiler plugin which inserts the simple or qualified name of a class at compile time. This preserves the name of the class even if it gets obfuscated using e.g. R8. This also works for targets where qualified names normally aren't available through reflection such as Kotlin/JS.
This plugin can only be added using Gradle:
plugins {
id("com.tebi.kompile-time-names") version "2.3.10-1.0.2"
}This snippet shows how the plugin can be used. The invocation of kompileTimeQualifiedName<SomeClass>() gets replaced
at compile time with the string constant "foo.bar.SomeClass".
package foo.bar
data class SomeClass(
val greeting: String,
)
println(kompileTimeQualifiedName<SomeClass>()) // This will print: foo.bar.SomeClass
println(kompileTimeSimpleName<SomeClass>()) // This will print: SomeClassThe kompileTime*Name() functions are defined as inline functions with a reified type parameter. This is
needed because the type needs to be known at compile time and can not be resolved dynamically at runtime.
It is possible to wrap these functions in your own function, but with the following restrictions:
@KompileTimeNames, and your type parameter with either
@WithQualifiedName or @WithSimpleName (or both), depending on which function you are going to use.Any).If any of the above requirements are not met you will get an error during compilation.
It is possible to nest multiple wrapper functions as long as the above requirements are met.
@KompileTimeNames
inline fun <@WithQualifiedName reified T : Any> someWrapperFunction(): String? {
return "wrapped:${kompileTimeQualifiedName<T>()}"
}Kompile-time names is a Kotlin Multiplatform compiler plugin which inserts the simple or qualified name of a class at compile time. This preserves the name of the class even if it gets obfuscated using e.g. R8. This also works for targets where qualified names normally aren't available through reflection such as Kotlin/JS.
This plugin can only be added using Gradle:
plugins {
id("com.tebi.kompile-time-names") version "2.3.10-1.0.2"
}This snippet shows how the plugin can be used. The invocation of kompileTimeQualifiedName<SomeClass>() gets replaced
at compile time with the string constant "foo.bar.SomeClass".
package foo.bar
data class SomeClass(
val greeting: String,
)
println(kompileTimeQualifiedName<SomeClass>()) // This will print: foo.bar.SomeClass
println(kompileTimeSimpleName<SomeClass>()) // This will print: SomeClassThe kompileTime*Name() functions are defined as inline functions with a reified type parameter. This is
needed because the type needs to be known at compile time and can not be resolved dynamically at runtime.
It is possible to wrap these functions in your own function, but with the following restrictions:
@KompileTimeNames, and your type parameter with either
@WithQualifiedName or @WithSimpleName (or both), depending on which function you are going to use.Any).If any of the above requirements are not met you will get an error during compilation.
It is possible to nest multiple wrapper functions as long as the above requirements are met.
@KompileTimeNames
inline fun <@WithQualifiedName reified T : Any> someWrapperFunction(): String? {
return "wrapped:${kompileTimeQualifiedName<T>()}"
}