lburgazzoli
07/14/2020, 5:18 PMasad.awadia
07/15/2020, 8:30 PMH.An
07/20/2020, 7:41 AMSergio Pro
07/29/2020, 1:16 PM@Import
annotation does not seem to be working for me:
`common.main.kts`:
#!/usr/bin/env -S kotlinc -script --
val greeting = "Hello"
`sample.main.kts`:
#!/usr/bin/env -S kotlinc -script --
@file:org.jetbrains.kotlin.script.util.Import("common.main.kts")
print(greeting) // unresolved reference and nothing to import
Both files are in the same directory and I've tried relative and absolute paths. Am I doing something wrong here?
I know it's possible with kscript
but I would prefer to keep extra dependencies to a minimum. Doesn't kotlin have built-in support for this and I'm totally misunderstanding what @Import
annotation is supposed to do?SrSouza
08/17/2020, 6:37 PMMETA-INF/kotlin/script/import.list
with all the implicit imports provided to the script that uses my library as a dependency (with the @file:DependOn()
)SrSouza
08/18/2020, 12:14 AMlaht
08/18/2020, 11:15 AMSrSouza
08/18/2020, 1:23 PMMavenDependenciesResolver
(by using scripting-dependencies-maven
)? I could find a way with the Ivy (my implementation: https://github.com/DevSrSouza/Bukkript/blob/master/script-definition/src/main/kotlin/br/com/devsrsouza/bukkript/script/definition/dependencies/IvyResolver.kt#L85)Steve Roach
08/18/2020, 2:12 PMJakub Gwóźdź
08/18/2020, 3:26 PM#!/usr/bin/env kotlinc -Xadd-modules=java.sql -script
@file:DependsOn("mysql:mysql-connector-java:8.0.19")
import java.sql.DriverManager
... actual code
now the problem is, that I cannot use AutoCloseable.use { .... }
extension function, because it's not in common/jvm stdlib.
How can I force kotlinc to use -jdk8 stdlib?Lukas Morawietz
08/18/2020, 4:57 PMSrSouza
08/19/2020, 12:44 PMjw
08/21/2020, 3:15 PM-d out
has no effect, and obviously I cannot compile without -script
.SrSouza
08/24/2020, 12:08 PMjava.lang.NoClassDefFoundError: com/intellij/openapi/util/Disposer
when running my Script Compiler.
The dependency that I'm using is kotlin-scripting-jvm-host
, I check it at the final jar and the com/intellij
actually missing, any idea here?Vampire
08/25/2020, 5:15 PMbuildscript {
dependencies {
classpath(kotlin("scripting-jsr223", "1.3.72"))
}
}
And then I tried to do
println("kt: " + javax.script.ScriptEngineManager().getEngineByExtension("kt"))
but it does not work.
The output is
ScriptEngineManager providers.next(): javax.script.ScriptEngineFactory: Provider kotlin.script.experimental.jsr223.KotlinJsr223DefaultScriptEngineFactory could not be instantiated
kt: null
If I use the debugger, I can extract this stacktrace:
java.util.ServiceConfigurationError: javax.script.ScriptEngineFactory: Provider kotlin.script.experimental.jsr223.KotlinJsr223DefaultScriptEngineFactory could not be instantiated
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:581)
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:803)
at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:721)
at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1394)
at java.scripting/javax.script.ScriptEngineManager.initEngines(ScriptEngineManager.java:125)
at java.scripting/javax.script.ScriptEngineManager.init(ScriptEngineManager.java:87)
at java.scripting/javax.script.ScriptEngineManager.<init>(ScriptEngineManager.java:62)
at Build_gradle.<init>(build.gradle.kts:118)
[...]
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalArgumentException: Unable to construct script definition: Unable to load base class kotlin.script.experimental.api.KotlinType@428395ed
at kotlin.script.experimental.host.ConfigurationFromTemplateKt.getTemplateClass(configurationFromTemplate.kt:101)
at kotlin.script.experimental.host.ConfigurationFromTemplateKt.createCompilationConfigurationFromTemplate(configurationFromTemplate.kt:37)
at kotlin.script.experimental.jsr223.KotlinJsr223DefaultScriptEngineFactory.<init>(KotlinJsr223DefaultScriptEngineFactory.kt:74)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:779)
... 168 more
Caused by: java.lang.IllegalArgumentException: unable to load class kotlin.script.experimental.jsr223.KotlinJsr223DefaultScript
at kotlin.script.experimental.jvm.JvmGetScriptingClass.invoke(jvmScriptingHostConfiguration.kt:111)
at kotlin.script.experimental.jvm.JvmGetScriptingClass.invoke(jvmScriptingHostConfiguration.kt:64)
at kotlin.script.experimental.host.ConfigurationFromTemplateKt.getTemplateClass(configurationFromTemplate.kt:99)
... 175 more
Caused by: java.lang.ClassNotFoundException: kotlin.script.experimental.jsr223.KotlinJsr223DefaultScript
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at kotlin.script.experimental.jvm.JvmGetScriptingClass.invoke(jvmScriptingHostConfiguration.kt:109)
... 177 more
Anyone have any idea?
Or is there maybe onther way to use Kotlin scripting?
Actually what I need is, I have a Kotlin file with an object expression and I need that object expression as reference.
But as it is in buildSrc/build.gradle.kts
I have no compile task where I could throw this in and it is 1. too long to just paste it into the build script and I 2. need it in a later phase too and wanted to avoid copy&pastealtavir
08/30/2020, 11:34 AMERROR Class 'hep.dataforge.workspace.WorkspaceBuilder' is compiled by a new Kotlin compiler backend and cannot be loaded by the old compiler (script.kts:3:1)
java.lang.IllegalStateException: ERROR Class 'hep.dataforge.workspace.WorkspaceBuilder' is compiled by a new Kotlin compiler backend and cannot be loaded by the old compiler (script.kts:3:1)
when interpreting a script from string. Why is that?SrSouza
09/01/2020, 4:07 PMMavenDependenciesResolver
to insert it on ide.dependenciesSources
?irus
09/02/2020, 7:03 PMCannot access script base class 'io.bootique.kotlin.config.ScriptingBQConfigurationScript'. Check your module classpath for missing or conflicting dependencies
Unresolved reference: addConfig
at io.bootique.kotlin.config.KotlinScriptCompilerTest.execute simple script config file(KotlinScriptCompilerTest.kt:36)
https://travis-ci.org/github/bootique/bootique-kotlin/jobs/723554789#L863
On JDK 11+ looks good:
https://travis-ci.org/github/bootique/bootique-kotlin/builds/723554788Nikky
09/05/2020, 9:50 AMdefaultImports.append("voodoo.dsl.*")
that show allow the script to use all extension functions declared in that package correct ?
i am facing some weird issues while trying to work on the DSL accessible from the scripts
errors like 'fun <E : NestedEntry> NestedEntry.Curse.list(initList: ListBuilder<NestedEntry.Curse>.() -> Unit): NestedEntry.Curse' can't be called in this context by implicit receiver. Use the explicit one if necessary
function looks like
fun <E: NestedEntry> E.list(
initList: ListBuilder<E>.() -> Unit
): E {
val listBuilder = ListBuilder(this)
listBuilder.initList()
// add all entries from list
entries += listBuilder.listEntries
return this
}
and i am not sure why it cannot be called on a receiver.. maybe the DSL markers mess it up..
but i call it directly on the object
and it also compiles in other parts of the code that are not compiled by scriptdarkmoon_uk
09/08/2020, 4:37 AMEgor
09/10/2020, 9:49 AMCzar
09/22/2020, 12:03 PMCould not find org.jetbrains.kotlin:kotlin-scripting-jsr223-embeddable:1.4.10.
Required by:
project :asdf:qwer
Is it just delayed so much behind Kotlin main, or should I switch to something else for embedded scripting?
I tried using 1.3.72 for scripting and 1.4.10 for the main application, but that doesn't work:
java.lang.NoSuchMethodError: 'void org.jetbrains.kotlin.cli.common.repl.GenericReplCompilingEvaluatorBase.<init>(org.jetbrains.kotlin.cli.common.repl.ReplCompiler, org.jetbrains.kotlin.cli.common.repl.ReplEvaluator, org.jetbrains.kotlin.cli.common.repl.ScriptArgsWithTypes, int, kotlin.jvm.internal.DefaultConstructorMarker)'
arocnies
09/24/2020, 5:07 AMvylet
09/28/2020, 6:32 PM@file:DependsOn("org.slf4j:slf4j-simple:1.7.30", exclude = "org.slf4j:slf4j-api")
arocnies
09/28/2020, 10:51 PM@Import
annotation that works the same way as simple version of main-kts
. Everything works fine when importing another script's function but I'm unable to import a class defined in the other script. It seems reasonable that classes defined in the script class's scope so I suspect I need my compilation configuration to do something to include them. Anyone know where I should be looking?SrSouza
10/05/2020, 10:28 PMscripting improvements
is postponed for later
, this means that you folks will stop improving it?Luis Munoz
10/06/2020, 3:41 PMholgerbrandl
10/07/2020, 8:43 PMlaht
10/09/2020, 7:45 AMMatthieu Stombellini
10/10/2020, 6:35 PMsealed class Test {
object One : Test()
object Two : Test()
}
test2.main.kts
@file:Import("test.main.kts")
println("I have one: " + Test.One)
println("I have two: " + Test.One)
Error:
$ kotlin
Welcome to Kotlin version 1.4.0 (JRE 14.0.1+7)
...
$ kotlin test2.main.kts
error: unresolved reference: Test (test2.main.kts:3:26)
error: unresolved reference: Test (test2.main.kts:4:26)
test2.main.kts:3:26: error: unresolved reference: Test
println("I have one: " + Test.One)
^
test2.main.kts:4:26: error: unresolved reference: Test
println("I have two: " + Test.One)
^
Is that supposed to happen? What am I missing here ?