Hi ! I've checked the docs for <compiling Java and...
# server
p
Hi ! I've checked the docs for compiling Java and Kotlin together with Maven, and I've scrupulously copied the pom.xml setup, however I'm still get
Unresolved Reference
for every single import in my
.kt
files. Using the builtin Intellij compiler works fine however ! Is this a known issue ?
l
this is more of a hint than an answer: i had that issue a loooong time ago trying to mix both in a single project - it turned out that maven would do EITHER "java, then kotlin" or "kotlin then java" compilation (at least then) i am not sure if that is still the case. so if you use BOTH kotlin classes from java and java classes from kotlin, that might be your issue as well.
i ended up splitting them apart (and then later scrapped all the java stuff)
p
really ???? there's no way I can do that in my case 😞
l
you could try swapping the plugin order in the pom, but i have a feeling you will have the opposite problem then (your java classes won't exist for your kotlin classes)
πŸ‘ 1
that seems to indicate that the kotlin plugin doesn't need the java classes
p
yeah πŸ€”
would it work if I put all the .kt files in a different directory ?
I thought I tried that though πŸ€”
l
maybe try a small sample project in github - less baggage makes this kind of thing easier to try πŸ™‚
...and if you DO get it working, share the trick - i would love to start using kotlin in some of my older projects
a
I've done it once. To mix kotlin and java in the same maven module, I've followed this tutorial : https://www.baeldung.com/kotlin/maven-java-project
πŸ‘ 2
p
That's what I've followed as well πŸ€”
might have missed smth, will review
a
Ensure to define kotlin compiler to execute before java compiler, and that your maven version is up-to-date (maven sometimes has nasty bugs, I've encounterdd more than once projects compilable only with latest maven)
p
I should be covered on that, but I could have missed a line somewhere in my pom file
I'm trying it right now with a clean and mostly empty project
πŸ‘ 1
Ok I made it work loading
I was missing the
kotlin-test
dependency (I thought this was used for tests only), as well as the
phase
elements in
kotlin-maven-plugin
's
executions
section
πŸ‘ 1
l
πŸ•Ί
p
So yeah indeed, Baeldung is king, as always !
πŸ‘ 1
Thanks a lot ! πŸŽ‰
l
cool, man - thanks for sharing the solution