simon.vergauwen
07/26/2021, 3:26 PMmodules: List<DModule> from PreMergeDocumentableTransformer (trying to do it as soon as possible in Dokka when info is available) I end up with DocTag.CodeBlock but that is again nested with more CodeBlock.
Trying to reconstruct the original code fence from the CodeBlock feels a bit off. Is there a way I can collect the CodeBlock as a simple String?Marcin Aman
07/26/2021, 5:26 PMsimon.vergauwen
07/26/2021, 8:27 PMsimon.vergauwen
07/26/2021, 8:27 PMMarcin Aman
07/27/2021, 8:48 AMsimon.vergauwen
07/27/2021, 8:51 AMP and BR in CodeBlock?Marcin Aman
07/27/2021, 8:54 AMsimon.vergauwen
07/27/2021, 8:55 AMsimon.vergauwen
07/27/2021, 8:57 AMMarcin Aman
07/27/2021, 9:54 AMSamplesTransformer. If you were to check code that is passed in those 2 places i’d create a transformer for documentables and another one for pages. This transformer would look at the code and compile it using our analysis (this is an extension point in DokkaBase , you can check out the SamplesTransformer on some example on how to use it). After you have your analysis working, you need to get an error stream (somehow).Marcin Aman
07/27/2021, 9:56 AMsimon.vergauwen
07/27/2021, 1:16 PMsimon.vergauwen
07/27/2021, 1:19 PMKotlin 1.5.20 and Dokka 1.5 but it’s now results in java.lang.NoSuchMethodError within Dokka.simon.vergauwen
07/27/2021, 1:20 PMMarcin Aman
07/27/2021, 1:20 PMsimon.vergauwen
07/27/2021, 1:29 PMsimon.vergauwen
07/27/2021, 3:20 PMsimon.vergauwen
07/27/2021, 3:31 PMScriptEngine running.simon.vergauwen
07/27/2021, 4:00 PMimplementation("org.jetbrains.kotlin:kotlin-compiler:1.5.21")
implementation("org.jetbrains.kotlin:kotlin-script-util:1.5.21")
runtimeOnly("org.jetbrains.kotlin:kotlin-reflect:1.5.21")
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-compiler:1.5.21")
I think "org.jetbrains.kotlin:kotlin-compiler:1.5.21" is the problematic one, but I’m not 100% sure. It’s the only dependency shared with Dokka, kotlin-reflect is only used in the Gradle plugin.
Tried to exclude it from "org.jetbrains.dokka:dokka-base:$dokkaVersion" but that also didn’t work.
I’m getting following NoSuchMethod error without reaching my extension point.simon.vergauwen
07/27/2021, 4:00 PMsimon.vergauwen
07/27/2021, 4:02 PMval x: Int = 1 in the ScriptEngine.simon.vergauwen
07/27/2021, 4:02 PMsimon.vergauwen
07/27/2021, 4:04 PMsimon.vergauwen
07/27/2021, 4:26 PMsimon.vergauwen
07/28/2021, 12:08 PMScriptEngine to run within Dokka.
Seems to be because Dokka is hooking into the compiler phases, by injecting its own service? But I’m not 100% sure, I don’t have such deep knowledge especially after all the FIR/IR changes.
Can anyone guide me in the correct direction?
I think I’ve tried a mix of about all dependencies/exclusions that I could think of. There is more info in the thread.
'org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(com.intellij.openapi.Disposable, org.jetbrains.kotlin.config.CompilerConfiguration, org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles)'
java.lang.NoSuchMethodError: 'org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(com.intellij.openapi.Disposable, org.jetbrains.kotlin.config.CompilerConfiguration, org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles)'Marcin Aman
07/28/2021, 12:37 PMdokka-analysis module and see if your use-case is not covered by that?simon.vergauwen
07/28/2021, 12:42 PM/**
* Maps every elements of the [List] with [transform]
*
* ```kotlin:ank
* import io.kotest.assertions.shouldBe
*
* listOf(1, 2, 3)
* .map { it + 1 } shouldBe listOf(2, 3, 4)
*
*/
fun <A> List<A>.map(transform: (A) -> B): List<B> = ...```simon.vergauwen
07/28/2021, 12:45 PMScriptEngine. (This currently support Java & Kotlin in the “legacy” tool)simon.vergauwen
07/28/2021, 12:46 PMScriptEngine.Marcin Aman
07/28/2021, 12:49 PMsimon.vergauwen
07/28/2021, 1:10 PMilya.chernikov
07/28/2021, 3:13 PMkotlin-scripting-jsr223 jar instead of using these deps:
implementation("org.jetbrains.kotlin:kotlin-compiler:1.5.21")
implementation("org.jetbrains.kotlin:kotlin-script-util:1.5.21")
runtimeOnly("org.jetbrains.kotlin:kotlin-reflect:1.5.21")
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-compiler:1.5.21")
and registering the engine via src/main/resources/META-INF/services/javax.script.ScriptEngineFactory.
You only need to add
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-jsr223:1.5.21")
instead, and hopefully it will work right away. If not - please ping me again, I'll need to dig a bit deeper then.simon.vergauwen
07/28/2021, 3:15 PMsimon.vergauwen
07/28/2021, 3:59 PMruntimeOnly("org.jetbrains.kotlin:kotlin-scripting-jsr223:1.5.21") but simply having that makes Dokka fail.
Also on the default Dokka Plugin Template, it’s reproducible by simply adding runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-jsr223:1.5.21").simon.vergauwen
07/28/2021, 4:04 PMilya.chernikov
07/28/2021, 4:19 PMMarcin Aman
07/28/2021, 4:21 PMsimon.vergauwen
07/28/2021, 4:22 PMilya.chernikov
07/28/2021, 4:24 PMMarcin Aman
07/28/2021, 4:26 PMilya.chernikov
07/28/2021, 4:26 PMkotlin-scripting-jsr223-unshaded instead of the regular one?simon.vergauwen
07/28/2021, 4:26 PMilya.chernikov
07/28/2021, 4:31 PMkotlin-compiler from transitive dependencies of the jsr-223 jar.ilya.chernikov
07/28/2021, 4:38 PMsimon.vergauwen
07/28/2021, 4:40 PMkotlin-scripting-jsr223-unshaded it doesn’t crash while starting Dokka anymore, but the dance with errors have begun again when touching the script engine.simon.vergauwen
07/28/2021, 4:42 PMruntimeOnly("org.jetbrains.kotlin:kotlin-scripting-jsr223-unshaded:1.5.21") {
exclude("org.jetbrains.kotlin", "kotlin-compiler")
}
// wired to Dokka
object AnkCompiler : PreMergeDocumentableTransformer {
val classLoader = URLClassLoader(emptyList<String>().map { URL(it) }.toTypedArray())
val seManager = ScriptEngineManager(classLoader)
val engine = requireNotNull(seManager.getEngineByExtension("kts")) { "getEngineByExtension" }
override fun invoke(modules: List<DModule>): List<DModule> =
modules.also { engine.eval("val x: Int = 1") }
}
&
kotlin.script.experimental.jsr223.KotlinJsr223DefaultScriptEngineFactory in META-INF.simon.vergauwen
07/28/2021, 4:43 PMruntimeOnly("org.jetbrains.kotlin:kotlin-scripting-jsr223-unshaded:1.5.21") without excluding the compiler dependency. Same code.
All this testing is done in the Dokka Plugin Template, to have a clean testground.ilya.chernikov
07/28/2021, 4:56 PMkotlin.script.experimental.jsr223.KotlinJsr223DefaultScriptEngineFactory in the META-INF, you don't need it at all with the new jsr-223 implementation.ilya.chernikov
07/28/2021, 4:57 PMsimon.vergauwen
07/28/2021, 4:59 PMsimon.vergauwen
07/28/2021, 5:00 PMilya.chernikov
07/28/2021, 5:03 PMkotlin-compiler jar and shadows it as kotlin-analysis-compiler (as Marcin mentioned above - https://github.com/Kotlin/dokka/blob/master/kotlin-analysis/compiler-dependency/build.gradle.kts and as visible in the classpath too). In this form the only easy possibility is to convince jsr-223 jar to use it as a dependency instead of the regular kotlin-compiler. And it may work only with -unshaded jsr-223. Theoretically I cannot yet imagine why it shouldn't work, so I'd try it.
Otherwise some isolation is needed.simon.vergauwen
07/28/2021, 5:12 PMilya.chernikov
08/09/2021, 11:18 AMruntimeOnly("org.jetbrains.kotlin:kotlin-scripting-jsr223-unshaded:1.5.21") { isTransitive = false }
(turning off transitivity doesn't work for me with the kotlin helper, I haven't checked how to deal with it).
Please try it in more advanced scenarios.simon.vergauwen
08/09/2021, 11:19 AMsimon.vergauwen
08/09/2021, 2:55 PMScriptEngine?
I updated my code, and when I try to evaluate a simple snippet. val x: Int = 1 or println("HELLO") it crashes.
Attempted both with -and without kotlin-std-jdk8 loaded into the classpath of the ScriptEngine.ilya.chernikov
08/10/2021, 10:04 AMPackageViewDescriptorFactory class arises due to the mismatch.ilya.chernikov
08/10/2021, 10:11 AMruntimeOnly(kotlin("reflect"))
runtimeOnly(kotlin("script-runtime"))
runtimeOnly("org.jetbrains.kotlin:kotlin-script-runtime:1.5.0") { isTransitive = false }
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-jsr223-unshaded:1.5.0") { isTransitive = false }
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-common:1.5.0") { isTransitive = false }
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-jvm:1.5.0") { isTransitive = false }
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-jvm-host-unshaded:1.5.0") { isTransitive = false }
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-compiler:1.5.0") { isTransitive = false }
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-compiler-impl:1.5.0") { isTransitive = false }
this is quite likely could be simplified, either by depending on the jsr223 one and excluding only kotlin-compiler (I keep forgetting gradle voodoo around dependencies handling), or by using some dependencies that do not depend on the compiler transitively.ilya.chernikov
08/10/2021, 10:23 AMval classLoader = AnkCompiler::class.java.classLoader.let { it as? URLClassLoader }?.let {
URLClassLoader(
it.urLs.filter {
it.file.contains("/kotlin-script") ||
it.file.contains("/kotlin-stdlib") ||
it.file.contains("/kotlin-reflect") ||
it.file.contains("/kotlinx-coroutines") ||
it.file.contains("/kotlin-analysis-compiler")
}.toTypedArray(),
null
)
}
System.setProperty("kotlin.jsr223.experimental.resolve.dependencies.from.context.classloader", "true")
Thread.currentThread().contextClassLoader = classLoader
ScriptEngineManager(classLoader).getEngineByExtension("kts").eval("println(31313131)")
I wasn't able to understand exacly what is going wrong here, maybe there is ann easier way to achieve the same isolation level.
Note the line that set obscure system property - this is optional and experimental, but may save some memory.
And setting the context classloader is needed for the engine to correctly define the compilation classpath.ilya.chernikov
08/10/2021, 10:27 AMsimon.vergauwen
08/10/2021, 10:28 AMsimon.vergauwen
08/10/2021, 12:41 PMsimon.vergauwen
08/10/2021, 7:17 PMilya.chernikov
08/11/2021, 8:26 AMsimon.vergauwen
08/11/2021, 1:49 PMsimon.vergauwen
08/11/2021, 1:49 PM