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.

Java sources (.java) matched by srcs compile jointly with the Kotlin sources. kotlinc reads the Java sources so Kotlin can reference Java declarations, then javac compiles the Java sources against the Kotlin classes, so Java can reference Kotlin declarations too. Both class trees are merged into the archive with fixed entry timestamps and permissions, so the archive bytes depend only on the class files. javac receives --release derived from jvm_target (1.8 becomes 8) unless javac_opts sets --release, -source, or -target. 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
manifeststringnononePackage-relative JAR manifest input
jarstringnoresolved JDK toolOverride the JDK archive tool used with manifest
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
javacstringnohost toolOverride the Java compiler used for Java sources
javac_optslist<string>no[]Additional Java compiler arguments for Java sources

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.struo/out/<target>/<output>
Kotlin classes, with Java sources.struo/out/<target>/kotlin_classes
Java classes, with Java sources.struo/out/<target>/java_classes

With manifest, compilation emits a declared classes tree and a separate archive action packages it with the supplied manifest using JDK 17 or newer jar. Archive entry timestamps are fixed, and the manifest contents and archive tool identity participate in caching. Without manifest or Java sources, kotlinc continues to emit the archive directly. Struo does not infer publication metadata or invent library versions.

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#

Resource packaging, Java annotation processing, Kotlin symbol processing, incremental compilation, and source-only interface archive generation are not implemented yet. Keep these steps behind a script target. Use java_import for prebuilt archives.