Skip to content

kotlin_jvm_library

Kotlin library for the Java virtual machine.

Description

Compiles Kotlin sources with kotlinc into one Java archive. The provider can feed other Kotlin targets and Android targets that accept java_library. Dependency roles distinguish normal, friend, exported, compile-only, and runtime-only classpaths.

Attributes

AttributeTypeRequiredDefaultDescription
module_namestringnotarget nameKotlin module name
outputstringno<target>.jarOutput Java archive file name
jvm_targetstringno17Java virtual machine bytecode target
language_versionstringnocompiler defaultKotlin language version
api_versionstringnocompiler defaultKotlin application programming interface version
kotlinc_optslist<string>no[]Additional Kotlin compiler arguments
compiler_plugin_jarslist<string>no[]Package-relative Kotlin compiler plug-in Java archives
compiler_plugin_optionslist<string>no[]Kotlin compiler plug-in options passed through -P
datalist<string>no[]Runtime data patterns propagated to binaries
kotlincstringnohost toolOverride the Kotlin compiler path
kotlin_homestringnoinferredKotlin installation root used to find the standard library
kotlin_stdlibstringnoinferredOverride the Kotlin standard library Java archive path
java_homestringnoJAVA_HOMEJava runtime home exposed to the compiler

Dependency Edges

EdgeAcceptsDescription
depskotlin_jvm_library, java_libraryLibraries used for compilation and runtime
associateskotlin_jvm_libraryFriend modules whose internal declarations are visible during compilation
exported_depskotlin_jvm_library, java_libraryLibraries exported to downstream compile and runtime classpaths
provided_depskotlin_jvm_library, java_libraryLibraries available for compilation but omitted from this target's runtime classpath
runtime_depskotlin_jvm_library, java_libraryLibraries added only to this target's runtime classpath

Declare named roles under [target.dependencies].

Providers

The target emits kotlin_jvm_library and java_library.

Provider Record

FieldTypeMeaning
compile_jarstringJava archive used on compile classpaths
runtime_jarstringJava archive used on runtime classpaths
transitive_compile_jarslist<string>Compile classpath propagated to consumers
transitive_runtime_jarslist<string>Runtime classpath propagated to consumers
transitive_datalist<string>Runtime data propagated to binaries

Capabilities

CapabilityOutput groups
builddefault, jar

Outputs

OutputLocation
Java archive.once/out/<target>/<output>

Example

toml
[[target]]
name = "Greeting"
kind = "kotlin_jvm_library"
srcs = ["src/main/kotlin/**/*.kt"]

[target.dependencies]
provided_deps = ["./CompileApi"]
runtime_deps = ["./RuntimeSupport"]

[target.attrs]
module_name = "greeting"
jvm_target = "17"

Limitations

Java source compilation, resource packaging, annotation processing, Kotlin symbol processing, incremental compilation, and source-only interface archive generation are not implemented yet. Use an Android target for mixed Android Java and Kotlin sources, or keep these steps behind a script target.

Released under an open-source license.