tapchicoma
03/24/2019, 12:48 PMKtxExec
task that, for now, supports only simple scripts (jcenter approval is pending)efemoney
03/30/2019, 3:40 AM*
).
The issue I’m facing is that in AS, with gradle, I have a service-def (script definitoin) module and a services (actual script files in src folder) module.
The services module gets its dependencies via gradle project dependencies (currently project(":service-def")
, project(":service-api")
and project(":service-dsl")
plus kotlin-stdlib and scripting-jvm dependencies). I also have a service-host module which I use to run the scripting host to debug issues and test out the scripts.
I really want to be able to specify only required jars while building the compilation configuration (only the api and dsl jars/classes should be visible within the scripts) but I cannot do this because, when resolved from intelliJ/AS, the classpath contains the actual jars like service-api-dev.jar
, but when I run the host module java app, the classpath contains folders with .class
files like .../api/build/classes/main/
. I think its a Gradle performance feature to avoid building the actual jars in the case of project dependencies. Would be great if I could specify *api*
and *dsl*
to filter the classpath as that would cover all the cases.
Current workaround is to use dependenciesFromCurrentContext(wholeClasspath = true)
which works but I dunno if I like. Also, the requirement for the jar version is too strict. As you can see from above my current version is dev because project is still in development. The current classpath filtering tries to strictly match semver like x.y.z and filters out my correct jars.
Final question: does scripting add the kotlin stdlib dep automatically? aka if I wanted a really small classpath, can I specify only api and dsl jars w/o explicitly specifying the stdlib and it will work? (My guess is no and we would have to add a kotlin compile config to compile with the stdlib or else specify it)
Final question 2: what classpath does the kotlin IJ/AS plugin use to determine dependencies for scripts? Like, if I open a custom script how is IJ/AS able to know the correct types. I know I have to have a jar in the classpath that contains script definition (in my case, I have to make sure to assemble/build the service-def module) but what classpath is IJ/AS checking exactlytapchicoma
04/01/2019, 6:30 PMAndrew Gazelka
04/10/2019, 3:19 PMkts
scripts linked together or would I be better off using kscript
?Andrew Gazelka
04/10/2019, 3:20 PMsdeleuze
04/12/2019, 9:42 AMsdeleuze
04/12/2019, 11:08 AMsdeleuze
04/12/2019, 11:10 AMaltavir
04/13/2019, 9:54 AMaltavir
04/13/2019, 10:56 AMaltavir
04/14/2019, 5:19 PMSrSouza
04/19/2019, 4:16 AMSlackbot
04/19/2019, 7:58 PMDALDEI
05/05/2019, 6:32 PMamanda.hinchman-dominguez
05/29/2019, 4:57 AMamanda.hinchman-dominguez
05/29/2019, 9:55 PMGradle: 4.8
Kotlin: 1.3.21
jonrengleman.shadow: 4.0.2
JDK: ZuluJDK8
Lorin
05/30/2019, 9:25 AM@KotlinScript(fileExtension = "simplescript.kts")
abstract class SimpleScript
fun main() {
val config = createJvmCompilationConfigurationFromTemplate<SimpleScript> {
jvm {
dependenciesFromCurrentContext(wholeClasspath = true)
}
}
val s = """
println("This is a test!")
""".trimIndent()
val res = BasicJvmScriptingHost().eval(s.toScriptSource("script-name"), config, null)
println(res)
}
Running this program, the following error is reported:
Failure(reports=[ScriptDiagnostic(message=Not a script file, severity=ERROR, sourcePath=null, location=null, exception=null)])
But if I remove the argument "script-name"
from s.toScriptSource()
. Everything will be fine. Could anyone from JB confirm it? Thanks!cedric
05/30/2019, 7:20 PM// a.kts
@file:org.jetbrains.kotlin.script.util.DependsOn("junit:junit:4.11")
org.junit.Assert.assertTrue(true)
Then:
$ kotlinc -classpath ~/.kobalt/cache/org/jetbrains/kotlin/kotlin-script-util/1.3.31/kotlin-script-util-1.3.31.jar a.kts
a.kts:3:5: error: unresolved reference: junit
org.junit.Assert.assertTrue(true)
^
$
ilya.chernikov
05/31/2019, 3:26 PMSrSouza
06/16/2019, 9:52 PMMrPowerGamerBR
06/17/2019, 3:40 PMwarning: default scripting plugin is disabled: The provided plugin org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar is not compatible with this version of compiler
and trying to execute anything throws an exception.gianluz
07/06/2019, 8:02 PMscript.main.kts
@file:Repository("<https://repo1.maven.org/maven2>")
@file:DependsOn("org.apache.commons:commons-text:1.6")
import org.jetbrains.kotlin.script.util.DependsOn
import org.jetbrains.kotlin.script.util.Repository
import org.apache.commons.text.WordUtils
val hello = "helloWorld"
print(hello)
print(WordUtils.capitalize(hello))
$: kotlinc -cp kotlin-main-kts-1.3.41.jar -script script.main.kts
script.main.kts:7:12: error: unresolved reference: apache
import org.apache.commons.text.WordUtils
^
script.main.kts:11:7: error: unresolved reference: WordUtils
print(WordUtils.capitalize(hello))
^
i do not understand what's wrong here.. 😢Gary Tierney
07/16/2019, 3:10 AMNikky
07/25/2019, 7:01 AMkotlinScriptDef
replace META-INF/kotlin/script/templates/...
? when using gradle ofc
and when i use this, do i change how i set up my folders in idea? currently i mark them as sources root so idea does highlightingNikky
07/25/2019, 9:54 AMGary Tierney
07/25/2019, 9:57 AMGerard de Leeuw
07/25/2019, 12:58 PMjdemeulenaere
07/31/2019, 3:04 PMBasicJvmScriptingHost
but I get a lot of weird errors and lost already so much time on this... In the end I just want a function that takes a String input (kotlin code) and outputs the printed output of the evaluated code, i.e:
evaluate("""println("Hello World")""") // returns "Hello World"
Gary Tierney
07/31/2019, 3:18 PMScriptEvaluator
to get a single return value from a script, but that's a bit different from capturing all printed outputjdemeulenaere
07/31/2019, 3:33 PMExecuting script...
[ERROR] Not a script file
Executed script