I want to compile some sample kotlin project using local compiler. I clone jetbrains/kotlin project from githib and build it. And now i have local compiler in /dist folder. How i need to configure gradle in sample project to use this local compiler in it and have an ability for remote debugging?
The simplest way is to build the whole toolchain and use it in your test projects.
To do that, run the install
Gradle task in the Kotlin project:
./gradlew install
This will publish all of the project's Maven modules to the Maven local repository (~/.m2/repository
by default) with the default snapshot version, which is 1.3-SNAPSHOT
at the moment.
Then, in your test Gradle project:
If you apply the Gradle plugin using a buildscript
block and an apply
statement, add the mavenLocal()
repository to buildscript { repositories { ... } }
and use the snapshot version of the Gradle plugin:
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3-SNAPSHOT")
}
}
If the plugins are applied using the plugins { ... }
block, modify the settings.gradle
script and add the following:
pluginManagement {
repositories {
mavenLocal()
gradlePluginPortal()
}
}
and again, use the 1.3-SNAPSHOT
version of the Gradle plugin:
plugins {
id("org.jetbrains.kotlin.jvm").version("1.3-SNAPSHOT")
}
In order to be able to debug the compiler, you need to run its process with a debugging agent waiting for a connection. Normally, the compiler is run in a daemon process that is harder to connect to. It's much simpler to run the compiler inside the Gradle process. To do that, you need to set a system property kotlin.compiler.execution.strategy
to in-process
in the Gradle process (note: this should be not a Gradle project property but a Java system property which can be passed by -Dkey=value
or set using System.setProperty(...)
.
Then run a Gradle build with a command line -Dorg.gradle.debug=true
to make Gradle wait for a remote debugger. I would advise for running the test project build from the terminal, not the IDE.
This will look like:
./gradlew compileKotlin -Dorg.gradle.debug=true -Dkotlin.compiler.execution.strategy=in-process
Starting a Gradle Daemon, 1 busy Daemon could not be reused, use --status for details
> Starting Daemon
(at this point, the build seems to hang, but it just waits for the debugger, so proceed below)
In the IDE where you work with the Kotlin project, put some breakpoints in the compiler code and attach the remote debugger to the Gradle process.
Note that, with the Kotlin compiler running inside the Gradle process, the latter may run out of memory sooner. Make sure the Gradle process gets enough heap space.