In the case of a maven project with Kotlin and Jav...
# getting-started
s
In the case of a maven project with Kotlin and Java side by side, the Kotlin docu (https://kotlinlang.org/docs/maven.html#compile-kotlin-and-java-sources) suggests this configuration
Copy code
<configuration>
    <sourceDirs>
        <sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
        <sourceDir>${project.basedir}/src/main/java</sourceDir>
    </sourceDirs>
</configuration>
but what do I do if I have a multi-module project?
${project.basedir}/src/main/kotlin
lacks the module in it's path, doesn't it?
v
I'm no Maven expert (not at all, ever), but afair
project.basedir
should be the base dir of the according module.
s
makes sense, but in that case I don't understand why the java-class can't find the Kotlin class
Copy code
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (java-compile) on project erezept-lib: Compilation failure
[ERROR] /home/stephan/workspace/erp-modul/erezept-lib/src/main/java/de/gematik/titus/erezept/service/PreconditionService.java:[319,27] error: cannot find symbol
[ERROR]   symbol:   variable JwtUtil
[ERROR]   location: class PreconditionService
JwtUtil
is in the same package as
PreconditionService
but in the Kotlin src-root. IntelliJ likes it, but
mvn compile
leads to the error msg. I made sure to have the kotlin-maven-plugin right in front of the maven-compiler-plugin.
v
Maybe this helps: https://www.baeldung.com/kotlin/maven-java-project Order is not enough
s
I've also disabled default compile and testCompile on the maven-compiler-plugin. I've done all there is in the baldung example 😕 Maybe it's one of the other plugins maven-source-plugin, spring-boot-maven-plugin, jacoco-maven-plugin, sonar-maven-plugin, maven-surefire-plugin, maven-failsafe-plugin, maven-checkstyle-plugin, versions-maven-plugin that need to be configured to consider kotlin as well!?? 😬
v
¯\_(ツ)_/¯ Sorry, not touching Maven with a five-foot-pole if I can avoid it any way.
a
@Stephan Schroeder every module has a POM inside, hasn't it ? Multi-module is only the parent which does not have any source, correct ?
s
@AndreyVanDenHaag correct
a
@Stephan Schroeder well, it means every module has its own
sourceDirs
What is the issue ?
v
The issues / questions were: 1. does
project.basedir
include the module directory or is it the directory of the parent project 2. why do his Java classes not find the Kotlin classes of the same module
s
@AndreyVanDenHaag the issue is that after the setup the compilation fails:
Copy code
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (java-compile) on project erezept-lib: Compilation failure
[ERROR] /home/stephan/workspace/erp-modul/erezept-lib/src/main/java/de/gematik/titus/erezept/service/PreconditionService.java:[319,27] error: cannot find symbol
[ERROR]   symbol:   variable JwtUtil
[ERROR]   location: class PreconditionService
PreconditionService
is still a Java-class.
JwtUtil
was refactored to Kotlin, and since my config should be ok (but apparently it isn't), it shouldn't be an unfindable symbol during compilation. When I Strg+click on "JwtUtil" with the the IntelliJ editor window showing the source of
PreconditionSerice
, IntelliJ it jumps to the Kotlin file, no problem.