igor.wojda
04/15/2020, 9:25 AMSystem.getProperty("user.dir")
)Slackbot
04/17/2020, 12:36 PMketurn
04/23/2020, 7:04 PM.ws.kts
), but do I need .main.kts
instead of .ws.kts
to use dependencies?gammanik
04/24/2020, 2:36 PMClassLoaders
and scriptEngine
.
Im creating a scriptEngine and adding my dsl rules in there from the outer scope
File("/Users/Nikita/Documents/lib-support/dsl-lib-support/build/libs/dsl-lib-support.jar")
My script returns me Map<String, MethodToMark>. MethodToMark is a part of my dsl rules:
val res: Map<String, MethodToMark>? = engine.eval(script) as Map<String, MethodToMark>?
println(res!!["lib.LibClassOne.method1"] as MethodToMark)
But this code doesn’t work. When I’m calling res!!["lib.LibClassOne.method1"] as MethodToMark
it gives me an error:
java.lang.ClassCastException: class MethodToMark cannot be cast to class MethodToMark (MethodToMark is in unnamed module of loader <http://java.net|java.net>.URLClassLoader @79609006; MethodToMark is in unnamed module of loader <http://com.intellij.ide.plugins.cl|com.intellij.ide.plugins.cl>.PluginClassLoader @67f6ebd8)
So the problem is that I cannot cast cast the same class to itself because of the fifferent class loaders I guess.
Here is a come Image where I’m creating my scriptEngine and adding my dsl rules:
How do I solve it?iguissouma
04/26/2020, 7:58 AMaddamsson
04/26/2020, 3:40 PMimport kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
@Serializable
data class User(
val name: String
)
val user = User("jon")
val json = Json(JsonConfiguration.Stable)
val jsonData = json.stringify(User.serializer(), user)
val result = json.parse(User.serializer(), jsonData)
require(user == result)
which I try to run in a script but I get the following error:
ERROR Unresolved reference: serializer
I guess the problem is that this works with `kotlinx.serialization`'s annotation processing feature. Is it possible to get this working in a script?
This is how I run it:
private fun evalFile(scriptFile: File): ResultWithDiagnostics<EvaluationResult> {
val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<TestScript> {
jvm {
dependenciesFromCurrentContext(wholeClasspath = true)
}
}
val evalConfig = createJvmEvaluationConfigurationFromTemplate<TestScript> {
jvm {
this.mainArguments.put(arrayOf("1"))
}
}
return BasicJvmScriptingHost().eval(scriptFile.toScriptSource(), compilationConfiguration, evalConfig)
}
MrPowerGamerBR
05/09/2020, 11:15 AMedwinRNDR
05/10/2020, 10:32 AMhttps://www.youtube.com/watch?v=qdgnRct0_nw&feature=youtu.be&t=12428▾
J-P
05/13/2020, 1:15 AMmr_kay
05/20/2020, 6:51 PM@KotlinScript(
fileExtension = "siteCost.kts",
compilationConfiguration = SiteCostScriptCompilationConfiguration::class,
evaluationConfiguration = SiteCostScriptEvaluationConfiguration::class
)
abstract class SiteCostScript(val arg: String)
for the time being, the constructor arg is directly passed in the `EvaluationConfiguration`:
object SiteCostScriptEvaluationConfiguration : ScriptEvaluationConfiguration({
constructorArgs("hugo")
})
however, if the script is evaluated using the following code
fun <T> eval(scriptString: String, resultClass: Class<T>): T {
val jvmScriptingHost = BasicJvmScriptingHost().eval(
scriptString.toScriptSource(),
SiteCostScriptCompilationConfiguration,
SiteCostScriptEvaluationConfiguration
)
return (resultWithDiag.valueOrThrow().returnValue as ResultValue.Value).value as T
}
I get an Exception (abbreviated)
java.lang.RuntimeException: java.lang.IllegalArgumentException: wrong number of arguments
at kotlin.script.experimental.api.ErrorHandlingKt.valueOrThrow(errorHandling.kt:240)
at com.zitecs.ologis.modules.ologisscriptengine.sitecost.control.kotlinscripting.SiteCostScriptingHost.eval(SiteCostScriptingHost.kt:19)
at com.zitecs.ologis.modules.ologisscriptengine.sitecost.control.kotlinscripting.SiteCostScriptingHostTest.return ScCostAssessment(SiteCostScriptingHostTest.kt:40)
....
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.evalWithConfigAndOtherScriptsResults(BasicJvmScriptEvaluator.kt:95)
It seems BasicJvmScriptEvaluator.evalWithConfigAndOtherScriptsResults
tries to invoke a default constructor (without args) which does not exist.
What am I doing wrong? Am I supposed to implement my own ScriptEvaluator
?louiscad
05/24/2020, 8:06 PM~./m2
local repo, which didn't match what I released on a bintray repo.
How can I proceed without wiping my whole computer?jdemeulenaere
05/26/2020, 7:06 AM.main.kts
script ? If yes you can look at the script definition: https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-main-kts/src/org/jetbrains/kotlin/mainKts/scriptDef.kt#L70Paul Woitaschek
05/29/2020, 1:54 PM#!/usr/bin/env kotlin
. This works fine but when I want to call it with arguments I always have to put a --
first because else the commands are passed to kotlin and not to the script. I.e.
./my_script.main.kts -- --my-flag
Is there a way to define this so I dont have to call --
first?Tmpod
05/31/2020, 2:16 PMDaren Klamer
06/08/2020, 3:43 AMclass Lamp {
// property (data member)
private var isOn: Boolean = false
// member function
fun turnOn() {
isOn = true
}
// member function
fun turnOff() {
isOn = false
}
fun displayLightStatus(lamp: String) {
if (isOn == true)
println("\$lamp lamp is on.")
else
println("\$lamp lamp is off.")
}
}
fun main(args: Array<String>) {
val l1 = Lamp() // create l1 object of Lamp class
val l2 = Lamp() // create l2 object of Lamp class
l1.turnOn()
l2.turnOff()
l1.displayLightStatus("l1")
l2.displayLightStatus("l2")
}
SrSouza
06/13/2020, 6:37 PMPaul Woitaschek
06/16/2020, 8:38 AM#!/usr/bin/env kotlin
@file:CompilerOptions("-Xopt-in=kotlin.time.ExperimentalTime","-jvm-target=1.8")
@file:DependsOn("com.github.ajalt:clikt:2.7.1")
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required
import com.github.ajalt.clikt.parameters.types.enum
enum class RPS {
Rock
}
class Application : CliktCommand(){
private val rps : RPS by option("--rps").enum<RPS>().required()
override fun run() {
println(rps)
}
}
Application().main(args)
This doesn't compile:
➜ scripts git:(features/huawei_health) ✗ ./test.main.kts -- --rps rock
error: cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option (test.main.kts:16:44)
test.main.kts:16:44: error: cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option
private val rps : RPS by option("--rps").enum<RPS>().required()
Daren Klamer
06/16/2020, 12:05 PMval compilationConfiguration = createJvmCompilationConfigurationFromTemplate<Any> {
compilerOptions("-jvm-target", "1.8", "-Xnew-inference", "-Xinline-classes")
jvm {
if (classLoader != null) {
dependenciesFromClassloader(
classLoader = classLoader,
wholeClasspath = true
)
} else {
dependenciesFromCurrentContext(
wholeClasspath = true
)
}
providedProperties(typeMap)
}
hostConfiguration(ScriptingHostConfiguration {
jvm {
val cacheExtSetting = System.getProperty(COMPILED_SCRIPTS_CACHE_DIR_PROPERTY)
?: System.getenv(COMPILED_SCRIPTS_CACHE_DIR_ENV_VAR)
val cacheBaseDir = when {
cacheExtSetting == null -> System.getProperty("java.io.tmpdir")
?.let(::File)?.takeIf { it.exists() && it.isDirectory }
?.let { File(it, "main.kts.compiled.cache").apply { mkdir() } }
cacheExtSetting.isBlank() -> null
else -> File(cacheExtSetting)
}?.takeIf { it.exists() && it.isDirectory }
//cacheBaseDir = File("/tmp")
if (cacheBaseDir != null)
compilationCache(
CompiledScriptJarsCache { script, scriptCompilationConfiguration ->
File(cacheBaseDir,
compiledScriptUniqueName(script, scriptCompilationConfiguration) + ".jar")
}
)
}
})
}
Nikky
06/20/2020, 1:23 PMkotlinx-html
to build a website
it seems to hang during compilation, 5 minutes and still hanging, first guess is too many functions with lambdas,
this is the code: https://gist.github.com/9d9cfa8dd17ad7650d4fbf203e0f2607
short tests of 10-20 lines and just a few things seemed to work fineSrSouza
06/26/2020, 10:06 PMSrSouza
06/29/2020, 9:26 PMSrSouza
07/01/2020, 2:05 AMbk.kts
and I try to create a New File Action at the IntelliJ and my extension is beeing removed, any work around or there is a better way to do that?Matthieu Stombellini
07/01/2020, 3:13 PMJvmScriptCompiler
the Kotlin compiler complained about not finding ScriptCompilerProxy
in the classpath. I'm using kotlin-scripting-jvm-host-embeddable
and I had to add kotlin-scripting-compiler-embeddable
as a dependency as well for the Kotlin compiler to find it. Is this normal? (1.3.72)Matthieu Stombellini
07/01/2020, 3:45 PMname
has a dot in it -- is this specified anywhere? (it failed in a weird way for me, it didn't detect the implicit receivers i set in the compilation configuration at all)SrSouza
07/03/2020, 11:23 PMactualClassLoader
in the Evaluation Configuration, but now, it is not available with public access, there is any alternative to it? to load the script in a my custom classloader?Egor
07/06/2020, 10:04 AMDuplicate JVM class name 'B_main' generated from: Myscript, Myscript
error.
In this case I used gradle for the build.
I tried with it with custom Kotlin script template as well as with ‘main.kts’ template. The result is the same.
I checked in gradle build
directory and saw that script generated classes resides on the top level and not in separate packages ( packageA
and packageB
).
How can I fix it?Dan T
07/07/2020, 10:49 PM#!/usr/bin/env kotlin
println("foo")
fails in IntelliJ 2020.1.2 with the following error:
error: org/jetbrains/kotlin/scripting/compiler/plugin/impl/KJvmCompiledModuleInMemory (foo.main.kts): java.lang.NoClassDefFoundError: org/jetbrains/kotlin/scripting/compiler/plugin/impl/KJvmCompiledModuleInMemory
I tried the 1.8
and 11.0.5
as JDKs.
Is this something that should be working currently? If not, is there an issue/page to track the progress of this? Thanks.SrSouza
07/09/2020, 4:16 AMefemoney
07/09/2020, 9:48 AMjvm-host-embeddable
has been removed (renamed?) in favor of jvm-host-unshaded
. Is this a simple artifact name change or are there other more detailed changes under the hood?jw
07/13/2020, 12:32 PM--
flags as arguments to a script? They are interpreted by kotlin rather than passed as arguments to my script. I tried using env -S kotlin --
as my shebang but kotlin
doesn't seem to support --
jw
07/13/2020, 12:32 PM--
flags as arguments to a script? They are interpreted by kotlin rather than passed as arguments to my script. I tried using env -S kotlin --
as my shebang but kotlin
doesn't seem to support --
$ ./test.main.kts --debug
error: invalid argument: --debug
info: use -help for more information
kenkyee
07/14/2020, 10:58 AMjw
07/14/2020, 5:01 PMargs
array