CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-jetbrains-kotlin--kotlin-script-util

Kotlin scripting support utilities library that provides infrastructure for implementing Kotlin script execution, including JSR-223 script engine implementations, dependency resolution, and utilities for classpath management in scripting contexts

Pending
Overview
Eval results
Files

dependency-resolution.mddocs/

Dependency Resolution (Deprecated)

The kotlin-script-util library provides deprecated dependency resolution infrastructure for Kotlin scripts using annotation-based declarations. This system allows scripts to declare dependencies and repositories using file-level annotations that are processed at script compilation time.

Note: All dependency resolution classes and annotations in this module are deprecated. Use the new annotation and processing code from the kotlin-scripting-dependencies library for new implementations.

Dependency Annotations

DependsOn

Annotation for declaring script dependencies using Maven coordinates or file paths.

@Deprecated("Use annotations an processing code from the kotlin-scripting-dependencies library")
@Target(AnnotationTarget.FILE)
@Repeatable
@Retention(AnnotationRetention.SOURCE)
annotation class DependsOn(
    val value: String = "",
    val groupId: String = "",
    val artifactId: String = "",
    val version: String = ""
)

Parameters:

  • value: String - Complete dependency string or file path
  • groupId: String - Maven group ID (alternative to value)
  • artifactId: String - Maven artifact ID (alternative to value)
  • version: String - Maven version (alternative to value)

Usage Examples:

// Using complete Maven coordinates
@file:DependsOn("org.apache.commons:commons-lang3:3.12.0")

// Using separate coordinate components
@file:DependsOn(groupId = "org.apache.commons", artifactId = "commons-lang3", version = "3.12.0")

// Using local file path
@file:DependsOn("./lib/my-library.jar")

// Multiple dependencies
@file:DependsOn("com.google.guava:guava:31.1-jre")
@file:DependsOn("org.slf4j:slf4j-api:1.7.36")

import org.apache.commons.lang3.StringUtils
import com.google.common.collect.Lists

println(StringUtils.capitalize("hello world"))
val list = Lists.newArrayList("a", "b", "c")

Repository

Annotation for declaring additional Maven repositories for dependency resolution.

@Deprecated("Use annotations an processing code from the kotlin-scripting-dependencies library")
@Target(AnnotationTarget.FILE)
@Repeatable
@Retention(AnnotationRetention.SOURCE)
annotation class Repository(
    val value: String = "",
    val id: String = "",
    val url: String = ""
)

Parameters:

  • value: String - Repository URL or local directory path
  • id: String - Repository identifier (optional)
  • url: String - Repository URL (alternative to value)

Usage Examples:

// Using Maven Central alternative
@file:Repository("https://repo1.maven.org/maven2/")

// Using repository with ID
@file:Repository(id = "spring-releases", url = "https://repo.spring.io/release/")

// Using local directory repository
@file:Repository("./local-repo")

// Using JCenter
@file:Repository("https://jcenter.bintray.com/")

@file:DependsOn("org.springframework:spring-core:5.3.21")

import org.springframework.util.StringUtils

Import (Deprecated)

Annotation for declaring script imports.

@Deprecated("Use your own annotations, this will be removed soon")
@Target(AnnotationTarget.FILE)
@Repeatable
@Retention(AnnotationRetention.SOURCE)
annotation class Import(vararg val paths: String)

Usage Example:

@file:Import("./utils/helpers.kts", "./config/settings.kts")

// Script content can now use declarations from imported scripts

CompilerOptions (Deprecated)

Annotation for specifying compiler options for script compilation.

@Deprecated("Use your own annotations, this will be removed soon")
@Target(AnnotationTarget.FILE)
@Repeatable
@Retention(AnnotationRetention.SOURCE)
annotation class CompilerOptions(vararg val options: String)

Usage Example:

@file:CompilerOptions("-Xjsr305=strict", "-Xjvm-default=all")

// Script compiled with specified compiler options

Dependency Resolvers

KotlinAnnotatedScriptDependenciesResolver

Main resolver that processes dependency annotations and resolves them using pluggable resolver implementations.

@Deprecated("Use new resolving classes from kotlin-scripting-dependencies and kotlin-scripting-dependencies-maven")
open class KotlinAnnotatedScriptDependenciesResolver(
    val baseClassPath: List<File>, 
    resolvers: Iterable<Resolver>
) : ScriptDependenciesResolver {
    
    @AcceptedAnnotations(DependsOn::class, Repository::class)
    fun resolve(
        script: ScriptContents,
        environment: Map<String, Any?>?,
        report: (ScriptDependenciesResolver.ReportSeverity, String, ScriptContents.Position?) -> Unit,
        previousDependencies: KotlinScriptExternalDependencies?
    ): Future<KotlinScriptExternalDependencies?>
}

Parameters:

  • baseClassPath: List<File> - Base classpath entries always included
  • resolvers: Iterable<Resolver> - Pluggable resolvers for different dependency types

Usage Example:

import org.jetbrains.kotlin.script.util.KotlinAnnotatedScriptDependenciesResolver
import org.jetbrains.kotlin.script.util.resolvers.DirectResolver
import org.jetbrains.kotlin.script.util.resolvers.FlatLibDirectoryResolver

// Create resolver with base classpath and multiple resolver implementations
val baseClasspath = listOf(File("./lib/base.jar"))
val resolvers = listOf(
    DirectResolver(), // For direct file paths
    FlatLibDirectoryResolver(File("./lib")) // For flat library directories
)

val dependencyResolver = KotlinAnnotatedScriptDependenciesResolver(baseClasspath, resolvers)

// The resolver processes @DependsOn and @Repository annotations in scripts

LocalFilesResolver

Simplified resolver for local file dependencies only.

@Deprecated("Use FileSystemDependenciesResolver from kotlin-scripting-dependencies instead")
class LocalFilesResolver : KotlinAnnotatedScriptDependenciesResolver(
    emptyList(), 
    arrayListOf(DirectResolver())
)

Usage Example:

import org.jetbrains.kotlin.script.util.LocalFilesResolver

// Used in script templates for local dependency resolution
val resolver = LocalFilesResolver()

// Automatically resolves @DependsOn annotations pointing to local files
// Example: @file:DependsOn("./lib/utility.jar")

Resolver Interface

Resolver

Base interface for dependency resolver implementations.

@Deprecated("Use new resolving classes from kotlin-scripting-dependencies")
interface Resolver {
    fun tryResolve(dependsOn: DependsOn): Iterable<File>?
    fun tryAddRepo(annotation: Repository): Boolean
}

Methods:

  • tryResolve: Attempts to resolve a DependsOn annotation to file paths
  • tryAddRepo: Attempts to add a repository from a Repository annotation

Basic Resolver Implementations

GenericRepositoryWithBridge

Bridge interface that combines GenericResolver and legacy Resolver interfaces.

@Deprecated("Use new resolving classes from kotlin-scripting-dependencies")
interface GenericRepositoryWithBridge : GenericResolver, Resolver {
    // Inherits from GenericResolver:
    // fun tryResolve(artifactCoordinates: GenericArtifactCoordinates): Iterable<File>?
    // fun tryAddRepository(repositoryCoordinates: GenericRepositoryCoordinates): Boolean
    
    // Inherits from Resolver:
    // fun tryResolve(dependsOn: DependsOn): Iterable<File>?
    // fun tryAddRepo(annotation: Repository): Boolean
}

DirectResolver

Resolves dependencies that are direct file or directory paths.

@Deprecated("Use new resolving classes from kotlin-scripting-dependencies")
class DirectResolver : GenericRepositoryWithBridge {
    // GenericResolver implementation
    fun tryResolve(artifactCoordinates: GenericArtifactCoordinates): Iterable<File>?
    fun tryAddRepository(repositoryCoordinates: GenericRepositoryCoordinates): Boolean
    
    // Resolver implementation
    fun tryResolve(dependsOn: DependsOn): Iterable<File>?
    fun tryAddRepo(annotation: Repository): Boolean
}

Usage Example:

import org.jetbrains.kotlin.script.util.resolvers.DirectResolver

val resolver = DirectResolver()

// Can resolve direct file paths in @DependsOn annotations
// Example: @file:DependsOn("./lib/my-library.jar")
// Example: @file:DependsOn("/absolute/path/to/library.jar")

FlatLibDirectoryResolver

Resolves dependencies by searching in flat library directories.

@Deprecated("Use new resolving classes from kotlin-scripting-dependencies")
class FlatLibDirectoryResolver(vararg paths: File) : GenericRepositoryWithBridge {
    fun tryResolve(artifactCoordinates: GenericArtifactCoordinates): Iterable<File>?
    fun tryAddRepository(repositoryCoordinates: GenericRepositoryCoordinates): Boolean
    
    companion object {
        fun tryCreate(annotation: Repository): FlatLibDirectoryResolver?
        fun tryCreate(repositoryCoordinates: GenericRepositoryCoordinates): FlatLibDirectoryResolver?
    }
}

Parameters:

  • paths: File - Directory paths to search for dependencies

Usage Example:

import org.jetbrains.kotlin.script.util.resolvers.FlatLibDirectoryResolver

// Create resolver for specific library directories
val resolver = FlatLibDirectoryResolver(
    File("./lib"),
    File("./third-party"),
    File("/usr/local/lib")
)

// Can resolve dependencies by filename in the specified directories
// Example: @file:DependsOn("commons-lang3-3.12.0.jar")

Generic Resolver Interfaces

GenericArtifactCoordinates

Interface representing artifact coordinates for dependency resolution.

@Deprecated("Use new resolving classes from kotlin-scripting-dependencies")
interface GenericArtifactCoordinates {
    val string: String
}

GenericRepositoryCoordinates

Interface representing repository coordinates.

@Deprecated("Use new resolving classes from kotlin-scripting-dependencies")
interface GenericRepositoryCoordinates {
    val string: String
    val name: String?
    val url: URL?
    val file: File?
}

BasicArtifactCoordinates

Basic implementation of artifact coordinates using string representation.

@Deprecated("Use new resolving classes from kotlin-scripting-dependencies")
open class BasicArtifactCoordinates(
    override val string: String
) : GenericArtifactCoordinates

BasicRepositoryCoordinates

Basic implementation of repository coordinates.

@Deprecated("Use new resolving classes from kotlin-scripting-dependencies")
open class BasicRepositoryCoordinates(
    override val string: String,
    override val name: String?
) : GenericRepositoryCoordinates {
    override val url: URL? = null
    override val file: File? = null
}

MavenArtifactCoordinates

Implementation for Maven-style artifact coordinates.

@Deprecated("Use new resolving classes from kotlin-scripting-dependencies")
open class MavenArtifactCoordinates(
    val value: String?,
    val groupId: String?,
    val artifactId: String?,
    val version: String?
) : GenericArtifactCoordinates {
    override val string: String // Computed Maven coordinate string
}

Complete Usage Example

// Script file example using dependency resolution annotations

@file:Repository("https://repo1.maven.org/maven2/")
@file:Repository("./local-lib")
@file:DependsOn("org.apache.commons:commons-lang3:3.12.0")
@file:DependsOn("./local-lib/custom-utility.jar")

import org.apache.commons.lang3.StringUtils
// Import from local-lib/custom-utility.jar would also be available

fun processText(input: String): String {
    return StringUtils.capitalize(StringUtils.trim(input))
}

println(processText("  hello world  ")) // "Hello world"

Migration Notes

When migrating to the new kotlin-scripting-dependencies library:

  1. Replace deprecated annotations:

    // Old
    import org.jetbrains.kotlin.script.util.DependsOn
    
    // New
    import kotlin.script.experimental.dependencies.DependsOn
  2. Replace resolver implementations with new equivalents from kotlin-scripting-dependencies

  3. Update script template definitions to use new dependency resolution APIs

Types

// From kotlin.script.dependencies package
interface ScriptDependenciesResolver {
    enum class ReportSeverity { FATAL, ERROR, WARNING, INFO, DEBUG }
    
    fun resolve(
        script: ScriptContents,
        environment: Map<String, Any?>?,
        report: (ReportSeverity, String, ScriptContents.Position?) -> Unit,
        previousDependencies: KotlinScriptExternalDependencies?
    ): Future<KotlinScriptExternalDependencies?>
}

interface KotlinScriptExternalDependencies {
    val classpath: Iterable<File>
    val imports: Iterable<String>
    val sources: Iterable<File>
}

interface ScriptContents {
    val annotations: Iterable<Annotation>
    val file: File?
    val text: CharSequence?
    
    data class Position(val line: Int, val col: Int)
}

Install with Tessl CLI

npx tessl i tessl/maven-org-jetbrains-kotlin--kotlin-script-util

docs

classpath-utilities.md

dependency-resolution.md

index.md

jsr223-engines.md

script-templates.md

tile.json