CLI Reference
swift4j-cli is the code generator that produces Kotlin and Java proxy classes from Swift source files. The generate-java-bridging SPM plugin invokes it automatically — use the CLI directly only when you need to integrate code generation into a custom build pipeline.
swift4j-cli [options] <swift-files...>Pass one or more .swift source files. The tool parses them, finds all @jvm-annotated types, and generates proxy classes.
Options
Section titled “Options”| Option | Required | Default | Description |
|---|---|---|---|
--package <name> | Yes | — | Java package name for the generated classes |
-o <dir> / --outdir <dir> | No | stdout | Directory to write generated files into |
--java-version <version> | No | 11 | Java language compatibility level |
--generate-android-viewmodels | No | off | Generate Android ViewModel wrappers for @Observable types |
Examples
Section titled “Examples”Generate to stdout (useful for inspection):
swift4j-cli --package com.example.mylib Sources/MyLib/Service.swiftGenerate to a directory:
swift4j-cli --package com.example.mylib \ -o generated/src/main/java \ Sources/MyLib/Service.swift \ Sources/MyLib/Models.swiftGenerate with Android ViewModel support:
swift4j-cli --package com.example.mylib \ --generate-android-viewmodels \ -o generated/src/main/java \ Sources/MyLib/*.swiftPackage naming
Section titled “Package naming”The --package value becomes the Java/Kotlin package declaration in all generated files. The generated class for a Swift type Foo in package com.example.mylib is imported in Kotlin as:
import com.example.mylib.FooWhen using the SPM generate-java-bridging plugin, the package name is derived automatically from the target name (hyphens replaced with underscores). Pass --package only when invoking the CLI directly.