I have a question about the semantics of the `java...
# compiler
t
I have a question about the semantics of the
javaSourceRoots
compiler option. Both
KaptOptions
and
K2JVMCompilerArguments
have a
javaSourceRoots
member. So far I have been passing both paths to Kotlin source files and Java source files as
K2JVMCompilerArguments.freeArgs
to the compiler and it has worked fine for the most part. Now we have noticed a problem that nested classes in Java sources can not be resolved by compiler plugins. This problem seems to go away when
javaSourceRoots
is set to the parent directory where the Java source files are located, but not when paths to the Java source files directly are added to
javaSourceRoots
. 1. Why can we give the compiler direct paths to Kotlin files but all the Java files have to be located in the same directory? We can see that the same parameter in
KaptOptions
accepts paths to files and not to a parent directory: https://github.com/JetBrains/kotlin/blob/e2521718ddef33d25158032dee649b1fa6f5b73a/[…]t3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt 2. Why is this option needed at all? The
K2JVMCompiler
is able to find and compile Java sources without it, but apparently not nested classes?
u
I don’t know about the kapt part of this at all, but accepting single .java files in the compiler was implemented as a kind of a hack, where we are running the Java lexer manually beforehand and are recording fully qualified names of all classes that we find: https://github.com/JetBrains/kotlin/blob/master/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/index/SingleJavaFileRootsIndex.kt IIRC running the Java parser was not feasible at this point because of performance reasons. There might very well be some bug in that code, that doesn’t catch some nested classes in some cases.