[Kapt related] Hi there, I generated a Kotlin file...
# kapt
m
[Kapt related] Hi there, I generated a Kotlin file in folder specified by
processingEnv.options["kapt.kotlin.generated"]
. Although everything works, Intellij is not recognizing generated classes (shown as errors). I tried to add the generated folder as a source directory, but still nothing.. any ideas? [11:13]
Copy code
sourceSets {
    main {
        java {
            srcDir "${buildDir.absolutePath}/generated/source/kaptKotlin/"
        }
    }
}
m
y
m
Oh, cool. Thanks for the answer. Have you also found some weird caching (I guess) problems when using
kapt3
. For example, I write an annotation processor, compile the project, and the code gets generated. Without changing anything I clean it and compile it again and the code is not generated. When I change something within the annotation processor, for example, I add a comment, clean, compile, and everything works. Basically, without changing anything, cleaning and compiling the project for the second time, doesn’t work. This doesn’t happen on previous version of
kapt
.
👍 1
I have another question regarding annotation processing. Not sure if it’s Kotlin related (I don’t think so), but maybe you can help me understand. I’d like to generate a Kotlin file from a template file. For example, all instances of template should be replaced with Driver. I tried putting the template file in the resources folder and load it with the following line
val source = javaClass.classLoader.getResource("template.vm").readText()
The problem is: - I can load only a file with a
.vm
extensions. Otherwise, I get the
FileNotFoundException
. I don’t understand why this happens.
@yan, any insights on this?
y
The issue with caching looks like a bug. Can you please submit it directly to http://kotl.in/issue? By the way, what annotation processor do you use? Can you provide some code example if it is possible? The latter looks very strange. Can you load the
.class
files, for example? E.g.,
javaClass.classLoader.getResource("kotlin/Unit.class")
?
m
Yeah, I’ll submit it when I find out how to reproduce it. 🙂 I realized that the above problem was caused by gradle. For example: I can load a
.txt
file for the first time. The next time, if I change the extension, it will not work. I have to restart the gradle daemon to make it work. Basically, right now, before every compile, I kill the gradle process to be sure that the changes are applied.
Btw. In my annotation processor, I want to check if the annotated object is extending an interface. How can I do that? (Check if the annotated element is an object and check if it’s implementing the interface?)