Is anyone generating Kotlin code using something o...
# announcements
d
Is anyone generating Kotlin code using something other than kapt? kapt is causing problems for me, because it does not work with IntelliJ's build system. And choosing "Delegate run actions to Gradle" does not work either, because it fails to properly rebuild all projects, so I am getting NoSuchMethodError, etc. And on top of all that, it is Java-only, meaning I am blocking myself from ging multiplatform in the future. My main question is: Is there some way to consume the Kotlin sources that are being compiled other than writing my own parser?
v
“Delegate run actions to Gradle” does not work either, because it fails to properly rebuild all projects,
are your gradle projects configured to use multipart project or composite build?
d
I have no idea what either of those means.
v
😛
d
I just use
compile (":foo")
in
dependencies
block
v
I’ll give links in a few minutes if you don’t find it by that time
d
ehm,
compile project(":foo")
I don't think I am using composite builds
v
no, you don’t if you don’t know about them 😛 - https://docs.gradle.org/current/userguide/composite_builds.html
d
Well, should I? lol
v
with them + delegation to gradle it rebuilds dependencies properly
so it’s a thing to try
d
okay I will take a look
g
Do you have particular reason to use Intellij build system instead of Gradle for your project?
d
Yes, delegating to gradle does not work, as I explained above
If it works as well as the IntelliJ system, I am fine with Gradle
t
I'm having no problems with IntelliJ, Gradle and kapt
d
Yes, it's not related to kapt (not working with the IntelliJ system at all). It's related to IntelliJ not building interconnected gradle projects properly.
t
I am afraid if kapt doesn't work for you you're pretty much out of luck. Kotlin codegen is the wild west right now and even the Java-specific tools we have are the bare minimum you could call functional
d
Yeah, I know. The generation itself works pretty well for me using Kotlin poet. It's when to do it and how to get my input data that's my issue.
t
with input data do you mean the Kotlin-specific syntax features, since `Element`s only see the code from a Java perspective? You can use Eugenio Marletti's kotlin-metadata library to read out most of those from the
@Metadata
annotations but it's pretty cumbersome to use. I am working on another library right now to integrate that with the Java
Element
API. Though that doesn't solve your problem of crossplatform codegen since it still builds on the Java-only annotation processing
d
kapt is one way to do it, which works. Like I said, it simply breaks for me since it only works when building with gradle and I cannot get that to work.
t
you can actually do cross platform annotation processing with kapt?
d
No
But even when sticking to just the JVM, it is not workable for me, since running a main class in Project A (with dependency on Project B in gradle) does not actually recompile Project B if "Delegate Build to gradle" is enabled.
It works fine in gradle itself and also using IntelliJ's own build system.
But the latter does not allow me to use kapt...
Still hoping for that compiler plugin API that has been promised many times
t
That's weird. I have multiple modules in my project that have gradle dependencies with
compile project(":foo")
and have "Delegate Build to Gradle" set and it seems to work (mostly). Maybe I just didn't notice that problem because I'm used to IntelliJ being crap and immediately delete the build folder whenever something doesn't get rebuilt
d
immediately delete the build folder whenever something doesn't get rebuilt
Ouch. This is why I write Kotlin and not Javascript 😄
g
Yes, delegating to gradle does not work, as I explained above
I’m not really understand your problem. First, do you have working Gradle project? Can you build your project from command line using Gradle? If so, I don’t see any problems with Idea, probably make sense to reimport project from Gradle module
Okay, I see, it works for your in Gradle
does not allow me to use kapt
What do you mean? As I said, try to reimport project. Close project and then “File” -> “New project from existing sources”
1
Also, maybe your run configuration is somehow wrong, try to run Gradle task from Idea instead
k
@diesieben07 Did you end up finding a workable solution? I'm having some of the same issues right now 😕
d
No, I basically gave in and used kapt.
Although I came across this: https://github.com/evanchooly/kibble, but I have not tried it.
k
Hmm, okay. I'll take a look at that project, seems similar to https://github.com/cretz/kastree. Neither of them helps for the gradle/idea integration unfortunately.
I guess it's just waiting for the stable compiler plugin API.
g
@karelpeeters What is your use case?
k
See the discussions in #C2R77UD35, that's my current use case. But more in general I want to be able to arbitrarily process code, modify it and generate new code before compilation.