what is the best template for writing compiler plu...
# compiler
s
what is the best template for writing compiler plugins? I'd like to have something with unit tests and sample project. I cannot find anything good enough. I can take existing project and just cut it down. any ideas?
It is set up for FIR + IR plugins, but it can be easily changed to K1 + IR configuration
s
thx
@dmitriy.novozhilov I love this project. it's all very cool. one thing I'm missing - it's my biggest issue with compiler plugins, to be honest. How can I connect it in Gradle to a new independent project and use this plugin independently? My issue is mostly with Gradle. kts - I don't get it for some reason(same as a pure grade). I tried copying stuff from StackOverflow, but it never works. Plus it would be very useful for other people as well. to have an independent module that is using that compiler plugin and it takes it from the .m2 folder. I have a very good idea for a compiler plugin, but I can only use it as a module - not independently. maybe another idea would be to deploy it remotely on some remote repo to make it visible by Gradle. or how would you convert that to maven? it has .m2 support out of the box.
d
it has .m2 support out of the box.
Gradle also supports
.m2
out of box, just add
mavenLocal()
to list of repositories. You also can add
maven("/some/path")
repository if you want to use some other directory than .m2
How can I connect it in Gradle to a new independent project and use this plugin independently?
You need to add your plugin using
-Xplugin=/path/to/plugin.jar
arguments in
freeCompilerArgs
for
compileKotlin
task Here is little example how to do it nice if you want to use plugin from some repo instead of manually set path to it:
Copy code
repositories {
    mavenCentral()
    mavenLocal() // points to ~/.m2
}

val compilerPlugin by configurations.creating

dependencies {
    compilerPlugin("my.awesome:plugin:0.0.1") // name and version of plugin
    testImplementation(platform("org.junit:junit-bom:5.8.0"))
    testImplementation("org.junit.jupiter:junit-jupiter")
}

val compileKotlin: KotlinCompile by tasks

compileKotlin.kotlinOptions {
    val pluginClasspath = compilerPlugin.files.joinToString(",") { it.canonicalPath }
    freeCompilerArgs += "-Xplugin=$pluginClasspath"
}
As for maven example, I can't help with it, because I'm not experienced in it and I don't like it
I'll change repo in that way so it will contain example of setting up plugin for some independent project The thing is that originally I created this repo for my students, and they have no need to really attach plugin to some real project
q
Is this compiler course public by any chance?
d
I'm not ready to share it too community yet And anyway it's in russian
t