https://kotlinlang.org logo
#k2-early-adopters
Title
# k2-early-adopters
j

jdiaz

03/19/2024, 8:55 PM
I'm trying the new k2 compiler with the 2.0 beta version. Trying to compile a .kt file with an stdlib call and it is asking for kotlin-home. Should it be asking for that when I'm using the compiler-embeddable dependency? Adding kotlin-home it works perfectly though
j

Javier

03/19/2024, 9:21 PM
What is kotlin-home
As tl;dr I'm using embeddable compiler to compile a file with
println("Hello")
and it is failing to find stdlib
👍 1
thank you color 1
t

tapchicoma

03/21/2024, 9:38 AM
yes, it should ask as we are not bundling
kotlin-stdlib
inside embeddable compiler
though it is weird that only with 2.0-Beta version you started to see this
j

jdiaz

03/21/2024, 5:04 PM
Is there a way to not need this, or have this home in the classpath or something?
t

tapchicoma

03/21/2024, 5:05 PM
Do you run
kotlinc
from command line?
j

jdiaz

03/21/2024, 5:06 PM
I'm doing it from inside a kotlin application
Copy code
val arguments = K2JVMCompilerArguments().apply {
            freeArgs = listFilesToCompile(project, target).map { it.absolutePath }
            classpath = project.classPath(target)
            kotlinHome = "/path/to/kotlin"
            destination = project.folder.resolve("build").resolve(target.name.lowercase()).absolutePathString()
            disableDefaultScriptingPlugin = true
        }
val code = compiler.exec(PrintingMessageCollector(System.out, MessageRenderer.PLAIN_FULL_PATHS, true), Services.EMPTY, arguments)
Like that
t

tapchicoma

03/21/2024, 5:17 PM
KGP always adds
-no-stdlib
and
-no-reflect
compiler options. And passes actual stdlib via classpath
j

jdiaz

03/21/2024, 5:18 PM
Actually that makes more sense, will do that!
Thanks thanks
t

tapchicoma

03/21/2024, 5:21 PM
I am curious - what is your use-case for invoking such way Kotlin compiler?
j

jdiaz

03/21/2024, 5:23 PM
I'm playing around a custom build system with a twist on dependency management
thank you color 1
Nothing serious at the moment, but I think gradle has become way too complicated and maven is way too verbose
2 Views