Kotlin v2.0.21 Help

Running KSP from command line

KSP is a Kotlin compiler plugin and needs to run with Kotlin compiler. Download and extract them.

#!/bin/bash # Kotlin compiler wget https://github.com/JetBrains/kotlin/releases/download/v2.0.21/kotlin-compiler-2.0.21.zip unzip kotlin-compiler-2.0.21.zip # KSP wget https://github.com/google/ksp/releases/download/2.0.21-1.0.25/artifacts.zip unzip artifacts.zip

To run KSP with kotlinc, pass the -Xplugin option to kotlinc.

-Xplugin=/path/to/symbol-processing-cmdline-2.0.21-1.0.25.jar

This is different from the symbol-processing-2.0.21-1.0.25.jar, which is designed to be used with kotlin-compiler-embeddable when running with Gradle. The command line kotlinc needs symbol-processing-cmdline-2.0.21-1.0.25.jar.

You'll also need the API jar.

-Xplugin=/path/to/symbol-processing-api-2.0.21-1.0.25.jar

See the complete example:

#!/bin/bash KSP_PLUGIN_ID=com.google.devtools.ksp.symbol-processing KSP_PLUGIN_OPT=plugin:$KSP_PLUGIN_ID KSP_PLUGIN_JAR=./com/google/devtools/ksp/symbol-processing-cmdline/2.0.21-1.0.25/symbol-processing-cmdline-2.0.21-1.0.25.jar KSP_API_JAR=./com/google/devtools/ksp/symbol-processing-api/2.0.21-1.0.25/symbol-processing-api-2.0.21-1.0.25.jar KOTLINC=./kotlinc/bin/kotlinc AP=/path/to/your-processor.jar mkdir out $KOTLINC \ -Xplugin=$KSP_PLUGIN_JAR \ -Xplugin=$KSP_API_JAR \ -Xallow-no-source-files \ -P $KSP_PLUGIN_OPT:apclasspath=$AP \ -P $KSP_PLUGIN_OPT:projectBaseDir=. \ -P $KSP_PLUGIN_OPT:classOutputDir=./out \ -P $KSP_PLUGIN_OPT:javaOutputDir=./out \ -P $KSP_PLUGIN_OPT:kotlinOutputDir=./out \ -P $KSP_PLUGIN_OPT:resourceOutputDir=./out \ -P $KSP_PLUGIN_OPT:kspOutputDir=./out \ -P $KSP_PLUGIN_OPT:cachesDir=./out \ -P $KSP_PLUGIN_OPT:incremental=false \ -P $KSP_PLUGIN_OPT:apoption=key1=value1 \ -P $KSP_PLUGIN_OPT:apoption=key2=value2 \ $*
Last modified: 26 十一月 2024