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
—
The kotlin-script-util library provides deprecated classpath management utilities that redirect to newer implementations in the kotlin-scripting-* libraries. These functions help with dynamic classpath resolution during script compilation and execution.
Note: All functions in this module are deprecated and redirect to kotlin.script.experimental.jvm.util. Use the new implementations directly for new code.
Extracts classpath entries from a ClassLoader.
@Deprecated("Use the function from kotlin.script.experimental.jvm.util")
fun classpathFromClassloader(classLoader: ClassLoader): List<File>?Parameters:
classLoader: ClassLoader - The ClassLoader to extract classpath fromReturns: List of classpath File entries, or null if extraction fails
Usage Example:
import org.jetbrains.kotlin.script.util.classpathFromClassloader
val classLoader = Thread.currentThread().contextClassLoader
val classpath = classpathFromClassloader(classLoader)
classpath?.forEach { file ->
println("Classpath entry: ${file.absolutePath}")
}Extracts classpath entries from the java.class.path system property.
@Deprecated("Use the function from kotlin.script.experimental.jvm.util")
fun classpathFromClasspathProperty(): List<File>?Returns: List of classpath File entries from system property, or null if not available
Usage Example:
import org.jetbrains.kotlin.script.util.classpathFromClasspathProperty
val systemClasspath = classpathFromClasspathProperty()
println("System classpath has ${systemClasspath?.size ?: 0} entries")Finds classpath entries containing a specific class.
@Deprecated("Use the function from kotlin.script.experimental.jvm.util")
fun classpathFromClass(
classLoader: ClassLoader,
klass: KClass<out Any>
): List<File>?Parameters:
classLoader: ClassLoader - The ClassLoader to search inklass: KClass<out Any> - The class to locate in the classpathReturns: List of classpath File entries containing the class, or null if not found
Usage Example:
import org.jetbrains.kotlin.script.util.classpathFromClass
import kotlin.script.templates.ScriptTemplateDefinition
val classLoader = Thread.currentThread().contextClassLoader
val classpath = classpathFromClass(classLoader, ScriptTemplateDefinition::class)
classpath?.forEach { file ->
println("Found ScriptTemplateDefinition in: ${file.absolutePath}")
}Finds classpath entries containing a class with the specified fully qualified name.
@Deprecated("Use the function from kotlin.script.experimental.jvm.util")
fun classpathFromFQN(
classLoader: ClassLoader,
fqn: String
): List<File>?Parameters:
classLoader: ClassLoader - The ClassLoader to search infqn: String - Fully qualified class name to locateReturns: List of classpath File entries containing the class, or null if not found
Usage Example:
import org.jetbrains.kotlin.script.util.classpathFromFQN
val classLoader = Thread.currentThread().contextClassLoader
val classpath = classpathFromFQN(classLoader, "org.jetbrains.kotlin.script.jsr223.KotlinStandardJsr223ScriptTemplate")
if (classpath != null) {
println("Found kotlin-script-util classes in: ${classpath.joinToString()}")
}Resolves classpath for script compilation from the current context.
@Deprecated("Use the function from kotlin.script.experimental.jvm.util")
fun scriptCompilationClasspathFromContext(
vararg keyNames: String,
classLoader: ClassLoader = Thread.currentThread().contextClassLoader,
wholeClasspath: Boolean = false
): List<File>Parameters:
keyNames: String - Names of JAR files or classpath keys to search forclassLoader: ClassLoader - ClassLoader to search in (defaults to current thread's context ClassLoader)wholeClasspath: Boolean - Whether to return the entire classpath or just matching entriesReturns: List of classpath File entries for script compilation
Usage Example:
import org.jetbrains.kotlin.script.util.scriptCompilationClasspathFromContext
// Get compilation classpath for kotlin-script-util
val classpath = scriptCompilationClasspathFromContext(
"kotlin-script-util.jar",
"kotlin-stdlib.jar",
wholeClasspath = true
)
println("Script compilation classpath:")
classpath.forEach { file ->
println(" ${file.name}")
}Safe version that returns null instead of throwing exceptions.
@Deprecated("Use the function from kotlin.script.experimental.jvm.util")
fun scriptCompilationClasspathFromContextOrNull(
vararg keyNames: String,
classLoader: ClassLoader = Thread.currentThread().contextClassLoader,
wholeClasspath: Boolean = false
): List<File>?Parameters: Same as scriptCompilationClasspathFromContext
Returns: List of classpath File entries, or null if resolution fails
Usage Example:
import org.jetbrains.kotlin.script.util.scriptCompilationClasspathFromContextOrNull
val classpath = scriptCompilationClasspathFromContextOrNull("kotlin-script-util.jar")
if (classpath != null) {
println("Successfully resolved ${classpath.size} classpath entries")
} else {
println("Failed to resolve script compilation classpath")
}Fallback version that returns stdlib classpath if context resolution fails.
@Deprecated("Use the function from kotlin.script.experimental.jvm.util")
fun scriptCompilationClasspathFromContextOrStdlib(
vararg keyNames: String,
classLoader: ClassLoader = Thread.currentThread().contextClassLoader,
wholeClasspath: Boolean = false
): List<File>Parameters: Same as scriptCompilationClasspathFromContext
Returns: List of classpath File entries, with stdlib as fallback
Usage Example:
import org.jetbrains.kotlin.script.util.scriptCompilationClasspathFromContextOrStdlib
// Always returns a valid classpath, falling back to stdlib if needed
val classpath = scriptCompilationClasspathFromContextOrStdlib("kotlin-script-util.jar")
println("Got ${classpath.size} classpath entries (including fallback if needed)")Checks if a file matches a base name, accounting for version suffixes.
@Deprecated("Use the function from kotlin.script.experimental.jvm.util")
fun File.matchMaybeVersionedFile(baseName: String): BooleanParameters:
baseName: String - Base name to match againstReturns: true if the file matches the base name (with or without version)
Usage Example:
import org.jetbrains.kotlin.script.util.matchMaybeVersionedFile
val kotlinStdlib = File("/path/to/kotlin-stdlib-1.8.22.jar")
val matches = kotlinStdlib.matchMaybeVersionedFile("kotlin-stdlib")
println("Matches kotlin-stdlib: $matches") // trueChecks if any parent directory has the specified name.
@Deprecated("Use the function from kotlin.script.experimental.jvm.util")
fun File.hasParentNamed(baseName: String): BooleanParameters:
baseName: String - Name to search for in parent directoriesReturns: true if any parent directory has the specified name
Usage Example:
import org.jetbrains.kotlin.script.util.hasParentNamed
val file = File("/home/user/projects/kotlin-project/src/Main.kt")
val inKotlinProject = file.hasParentNamed("kotlin-project")
println("File is in kotlin-project: $inKotlinProject") // trueDeprecated object that provides access to Kotlin compiler JARs.
@Deprecated("Use the object from kotlin.script.experimental.jvm.util")
val KotlinJars = kotlin.script.experimental.jvm.util.KotlinJarsUsage Example:
import org.jetbrains.kotlin.script.util.KotlinJars
// Access compiler classpath (redirects to new implementation)
val compilerClasspath = KotlinJars.compilerWithScriptingClasspath
println("Compiler classpath has ${compilerClasspath.size} entries")All functions in this module are deprecated and redirect to the new implementations in kotlin.script.experimental.jvm.util. When updating code:
Replace imports:
// Old
import org.jetbrains.kotlin.script.util.classpathFromClassloader
// New
import kotlin.script.experimental.jvm.util.classpathFromClassloaderFunction signatures remain the same, so no code changes are needed beyond imports
The new implementations provide better performance and additional features
// Standard Java types used by classpath utilities
typealias ClassLoader = java.lang.ClassLoader
typealias File = java.io.File
// Kotlin reflection types
import kotlin.reflect.KClassInstall with Tessl CLI
npx tessl i tessl/maven-org-jetbrains-kotlin--kotlin-script-util