https://kotlinlang.org logo
#kapt
Title
# kapt
e

epool

05/23/2018, 3:18 PM
I just built an annotation processor that generates a builder class for my classes annotated with
@DataBuilder
, my classes annotated with this annotation are located in
com.my.package.model
and the generated builder class is also located in the same package
com.my.package.model
but in the generated directory of course
build/generated/source/kapt/debug/com/my/package/model/MyModelBuilder.kt
, I can use these generated classes fine inside of my model classes(written in Kotlin) BUT I cannot use the generated
MyModelBuilder
Kotlin class inside of a java class as a class member
Copy code
package com.my.package.home;
import com.my.package.model.MyModelBuilder;
public class Home {
    MyModelBuilder builder; // <=== AS recognizes the class, but I'm having an compilation issue
}
AndroidStudio recognizes the class, but I’m having this compilation issue
Copy code
com/my/package/home/Home.java:4: error: cannot find symbol
MyModelBuilder builder;
           ^
  symbol:   class MyModelBuilder
  location: class Home
it’s weird because I can use this generated builder class only inside of methods, this code works fine
Copy code
package com.my.package.home;
import com.my.package.model.MyModelBuilder;
public class Home {
    public void hello() {
        MyModelBuilder builder;
    }
}
could somebody here help me to understand this behavior? In advance, thanks!
g

gildor

05/24/2018, 1:55 AM
I think it’s hard to help you using this information. Could you please reproduce it on a sample project
e

epool

05/24/2018, 3:46 AM
got it, I’ll create a project for trying to reproduce this
@gildor sorry, I just added the repo here https://github.com/epool/HelloKapt
g

gildor

05/24/2018, 5:47 AM
Hmm, I think that Android plugin be default do not add this dir to sourcesets
I suppose it should work if you add generated sources dir to source set:
Copy code
sourceSets {
        main.java.srcDirs +=  file("$buildDir/generated/source/kapt/")
}
but actually it’s really strange, it works on my project with other annotation processors
Oh, I got it, I use this code from Kotlin, your AP used from Java
I suppose there is some issue with order of AP/javac/kapt
Probably make sense to create an issue on Kotlin issue tracker
Even with sourceSets it doesn’t work for me on first run, only on second one, when all generated files are compiled
e

epool

05/24/2018, 3:27 PM
it’s weird because it works if I use the generated class inside of methods. thanks I just created an issue for this here https://youtrack.jetbrains.net/issue/KT-24591
8 Views