Symbol-export
Symbol-export is a tool for exporting symbols from Kotlin libraries so that they can be referenced by tooling such as compile plugins or annotation processors.
Features:
-
Compile time errors if symbol names change
-
Integrations with the Kotlin compiler, KSP, and Kotlinpoet
-
Reading and writing of annotation instances
Getting started
All you need to do is apply the Gradle plugins to the appropriate projects and add a dependency between the exported symbols and the project that uses them.
Exporting project
build.gradle.kts
plugins {
id("dev.rnett.symbol-export.export")
}
name = "foobar"
Your code
package foo.bar
@ExportSymbol
fun bar() {
}
@ExportSymbol
class FooService {
}
Importing project
build.gradle.kts
plugins {
id("dev.rnett.symbol-export.import")
}
dependencies {
importSymbols(project(":foobar"))
}
Your code
val bar = Symbols.foobar.foo_bar_bar
val fooService = Symbols.foobar.foo_bar_FooService
By default, the Symbols
object is generated with a package matching the importing project's group ID.
Then the importer project can import a Symbols
object containing the exported symbols for any declarations in exporter
marked with @ExportSymbol
(Symbol
's package defaults to the project's group ID).
Dependencies on the annotations and symbol library will be added automatically to the exporting and importing projects, respectively (this can be opted out of).
Usage
For more advanced usage, check out the available annotations and consult the configuration options of the Gradle plugins.
All modules:
Annotations to trigger and control the exporting of symbols.
The Gradle plugins for symbol-export.
Symbol definition types used in the code generated by importing symbols.
Integration between the generated symbol types and the Kotlin compiler types.
Integration between the generated symbol types and Kotlinpoet.
Integration between the generated symbol types and KSP.