A lightweight utility for checking the syntax correctness of .main.kts (Kotlin Script) files without executing them. This tool is particularly useful for developers working with CI/CD written in Kotlin.
- Fast Syntax Checking: Quickly verifies the syntax of
.main.ktsfiles without execution. - Dependency Resolution: Supports
@DependsOnand@Repositoryannotations for dependency management. - Command-Line Interface (CLI): Easy-to-use CLI for integrating into your development workflow.
- Continuous Integration Friendly: Ideal for use in CI/CD pipelines to ensure script quality.
- Caching: Intelligent caching of compiled scripts for faster subsequent runs.
git clone <repository-url>
cd kts-compiler
./gradlew buildAfter building, you can use the CLI directly:
./gradlew run --args="path/to/your/script.main.kts"Or use the generated script:
./build/scripts/kts-compiler path/to/your/script.main.kts# Check a single script
./gradlew run --args="script.main.kts"
# Check multiple scripts
./gradlew run --args="script1.main.kts script2.main.kts script3.main.kts"0- All scripts compiled successfully1- One or more scripts failed to compile
The tool provides clear feedback:
✅ Success: script.main.kts
❌ Error: failed-script.main.kts
ERROR Expecting an expression (failed-script.main.kts:7:14)
#!/usr/bin/env kotlin
println("Hello, World!")#!/usr/bin/env kotlin
@file:Repository("https://repo1.maven.org/maven2/")
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1")
import kotlinx.coroutines.runBlocking
runBlocking {
println("Hello from coroutines!")
}#!/usr/bin/env kotlin
@file:Repository("https://repo1.maven.org/maven2/")
@file:DependsOn("com.github.ajalt:clikt:4.4.0")
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
class MyCommand : CliktCommand() {
private val name: String by argument(help = "Name to greet")
override fun run() {
println("Hello, $name!")
}
}
MyCommand().main(args)Download jar and script from releases (recomended)
or build your own standalone JAR:
./gradlew shadowJarThen use the provided KTS script:
# Check single script
kotlinc -script check-kts-scripts.main.kts -- script.main.kts
# Check all scripts in directory
kotlinc -script check-kts-scripts.main.kts -- /path/to/scripts/name: Check KTS Scripts
on:
pull_request:
paths:
- '**/*.main.kts'
jobs:
check-scripts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build JAR
run: ./gradlew shadowJar
# place the JAR on the same node as the KTS script and adjust path to jar in the script
- name: Check KTS scripts
run: kotlinc -script check-kts-scripts.main.kts -- /path/to/your/scripts/check-kts-scripts:
stage: test
image: openjdk:17
script:
# place the JAR on the same node as the KTS script and adjust path to jar in the script
- kotlinc -script check-kts-scripts.main.kts -- /path/to/your/scripts/
only:
changes:
- "**/*.main.kts"- ✅ Kotlin Script syntax validation
- ✅ Dependency resolution via
@DependsOn - ✅ Repository configuration via
@Repository - ✅ Import statements validation
- ✅ Type checking
- ✅ Compilation error reporting
- ✅ Multiple file processing
- ✅ Caching for performance
- Currently supports only
.main.ktsscripts - Dependency resolution requires internet access
- Some advanced Kotlin features may not be fully supported
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License.