Running KSP from the command line
Most projects use KSP through the KSP plugin for Gradle that runs KSP automatically during compilation. As an alternative, you can also run KSP from the command line. This is useful if you integrate KSP with other build systems, develop processors, or test and debug the code.
Since KSP is a JVM application, use the java command to launch KSP from the command line. Provide the classpath and any necessary arguments:
Argument | Description |
|---|---|
| A path to the KSP runtime JAR files and their dependencies. |
| A platform-specific KSP entry point. |
| Command-line options for KSP. |
| A path to the processor JAR. |
Classpath
Unlike the KSP plugin for Gradle, the java command doesn't resolve dependencies automatically. You must provide the KSP runtime JAR files and their dependencies on the classpath.
Download artifacts.zip from the KSP release page on GitHub. The archive contains the required KSP JAR files:
symbol-processing-aa-2.3.12.jarsymbol-processing-common-deps-2.3.12.jarsymbol-processing-api-2.3.12.jar
You must also include the following runtime dependencies from the Maven repository:
Main class
Because KSP is a JVM application, you must specify the main class to launch. KSP provides a different entry point for each supported platform:
Entry point | Platforms |
|---|---|
| Kotlin/JVM and Android |
| Kotlin/JS |
| Kotlin/Native targets, such as iOS, macOS, Linux, and Windows |
| Common compilations in Kotlin Multiplatform projects |
When launching KSP with java, specify the fully qualified class name. For example:
The following example uses KSPJvmMain to run KSP for a JVM target:
Options
The KSPJvmMain entry point requires the following options:
Option | Description |
|---|---|
| Kotlin language version used in the project. |
| |
| Target JVM version. |
| Module name. |
| Source root directories. Use a colon-separated list for multiple directories. |
| Project root directory. |
| Base directory for KSP output. |
| Directory for KSP caches. |
| Directory for generated Java files. |
| Directory for generated class files. |
| Directory for generated Kotlin files. |
| Directory for generated resources. |
| Processor classpath. |
Other entry points use a different set of options. To see the full list of options for a specific entry point, run the following command:
Other options
-libraries=<path>: the classpath used to resolve dependencies referenced by the source files. This is typically the module's compile classpath.-jdk-home=<path>: the JDK home directory. Use when the processor resolves Java symbols and requires access to the Java standard library.-friends=<path>: the classpath of the current module's friend modules. For more information, refer to thefriendPathsproperty in the Kotlin Gradle plugin API reference.
See also
Learn how incremental processing works and how to debug it from the command line.
Learn how to use KSP in a Kotlin Multiplatform project with Gradle.