Maven, Android and Kotlin

Hi all,

I’m trying to build an Android project using the andoird-maven-plugin and the kotlin-maven-plugin. Basically, it’s working pretty well, instead of a small issue.

The android-maven-plugin auto-generates resource classes (R.class, BuildConfig.class, …) and places them under target/classes. The kotlin-maven-plugin runs afterwards and compiles kotlin sources that reference those resources and places them also under target/classes. Unfortuantely, the directory target/classes itself isn’t on the classpath so the referenced resources are not found. As a workaround, I’ve added the target directory to the classpath by doing this…

<configuration>   <sourceDirs>           <source>${basedir}/target/classes</source>           <source>${basedir}/src/main/kotlin</source>   </sourceDirs> </configuration>

...but this implies that I do a clean before every compile, because obviously all kotlin classes would already exists if not cleaned before.

Does anyone have an idea how to fix this?

Best regards,
Philipp

Hi Philipp, R-classes is an android-specific  feature and, as I already told you, kotlin-maven plugin for android isn't implemented yet. It seems that you will also have problems with kotlin external annotations for android sdk.

May be it isn’t too late to recommend you to use gradle as a build system?

Hello Natalia,

yeah, I had problems with the annotations. I solved it by adding the annotations jar to the dependencies.

I’ve changed the build system to gradle and it’s working much better now. The issue I’ve now is, that the kdoc task isn’t working anymore. It would be useful to have some documentation about how to set it up. Is there any? Or maybe some example code?

Best,
Philipp

Philip,

Thank you for reporting the issue
Currently, KDoc task is broken. We will fix it as soon as possible and release fixes in next version. Please watch/vote for this issue: http://youtrack.jetbrains.com/issue/KT-4612